Source

snowball / snowball_test.go

package snowball

import (
	"testing"
)

func TestList(t *testing.T) {
	if len(List()) == 0 {
		t.Fatal("No langs")
	}
}

func TestListEnglish(t *testing.T) {
	found := false
	for _, v := range List() {
		if v == "english" {
			found = true
			break
		}
	}

	if !found {
		t.Fatal("english not found")
	}
}

func TestNew(t *testing.T) {
	lang := "english"
	stemmer, err := New(lang)

	if err != nil {
		t.Fatalf("error creating english stemmer - %s", err)
	}

	if stemmer.Lang() != lang {
		t.Fatalf("lang is not english (is %s)", stemmer.Lang())
	}
}

func TestNewNoLang(t *testing.T) {
	lang := "klingon"
	_, err := New(lang)

	if err == nil {
		t.Fatal("dude, we have a klingon stemmer!")
	}
}

func check(t *testing.T, lang, word, stem string) {
	stemmer, err := New(lang)
	if err != nil {
		t.Fatalf("can't create stemmer for %s - %s", lang, err)
	}

	w := stemmer.Stem(word)
	if w != stem {
		t.Fatalf("error stemming '%s', got %s instead of '%s'", word, w, stem)
	}
}

func TestStemEn(t *testing.T) {
	check(t, "english", "running", "run")
}

func TestStemDe(t *testing.T) {
	check(t, "german", "käuflich", "kauflich")
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.