Miki Tebeka avatar Miki Tebeka committed 5dc57ef

New

Comments (0)

Files changed (2)

 package snowball
 
 import (
+	"fmt"
+	"runtime"
 	"unsafe"
 )
 
 
 // #include "libstemmer.h"
 import "C"
-/*
 type Stemmer struct {
+	lang string
 	stemmer *C.struct_sb_stemmer
 }
 
 // New creates a new stemmer for lang
 func New(lang string) (*Stemmer, error) {
 	stemmer := &Stemmer{
+		lang,
 		C.sb_stemmer_new(C.CString(lang), nil),
 	}
 
 	if stemmer.stemmer == nil {
-		return nil, fmt.Errorf("bad lang or charenc")
+		return nil, fmt.Errorf("can't create stemmer for lang %s", lang)
 	}
 
 	runtime.SetFinalizer(stemmer, free)
 	return stemmer, nil
 }
 
+func (stemmer *Stemmer) Lang() string {
+	return stemmer.lang
+}
+
+/*
 // Stem returns them stem of word (e.g. running -> run)
 func (stemmer *Stemmer) Stem(word string) string {
 	cstr := C.sb_stemmer_stem(stemmer.stemmer, C.CString(word), C.int(len(word)))
 		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!")
+	}
+}
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.