Commits

Miki Tebeka committed 128cb56

List works

Comments (0)

Files changed (2)

 package snowball
 
 import (
-	"fmt"
-//	"runtime"
+	"unsafe"
 )
 
 
-// FIXME: Currently cgo does not find the source files in libstemmer_c/
-
 // #include "libstemmer.h"
 import "C"
 /*
 
 // List returns the list of languages supported by snowball
 func List() []string {
-	cnames := C.sb_stemmer_list()
 	names := []string{}
-	for i := 0; true; i++ {
-		name := C.GoString(names[i])
-		if len(name) == 0 { // names is ended by sentinal of NULL
+
+	cp := uintptr(unsafe.Pointer(C.sb_stemmer_list()))
+	size := unsafe.Sizeof(uintptr(0))
+
+	for {
+		name := C.GoString(*(**C.char)(unsafe.Pointer(cp)))
+		if len(name) == 0 {
 			break
 		}
 		names = append(names, name)
+		cp += size
 	}
-
 	return names
 }
 	"testing"
 )
 
+/*
 func TestStem(t *testing.T) {
 	stemmer = New("en")
 	word = "running"
 		t.Fatalf("stem(%s) -> '%s' (expected 'run')", word, stemmed)
 	}
 }
+*/
+
+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")
+	}
+}