github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/utils/spellcheck/userdictionary/userdictionary_test.go (about) 1 package userdictionary 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/lmorg/murex/app" 8 "github.com/lmorg/murex/test/count" 9 ) 10 11 func TestIsIn(t *testing.T) { 12 count.Tests(t, 2) 13 14 positive := app.Name 15 negative := app.Name + "-unit-test-ertfyguhibgvcfdrtfyg" 16 17 if !IsInDictionary(positive) { 18 t.Errorf("%s should be in dictionary", positive) 19 } 20 21 if IsInDictionary(negative) { 22 t.Errorf("%s should NOT be in dictionary", negative) 23 } 24 } 25 26 func TestGet(t *testing.T) { 27 count.Tests(t, 1) 28 29 a := Get() 30 31 if len(dictionary) != len(a) { 32 t.Error("len doesn't match") 33 } 34 } 35 36 func TestRead(t *testing.T) { 37 count.Tests(t, 1) 38 39 v, err := Read() 40 if err != nil { 41 t.Error(err) 42 } 43 44 if len(v.([]string)) != len(dictionary) { 45 t.Error("len doesn't match") 46 } 47 } 48 49 func TestWrite(t *testing.T) { 50 count.Tests(t, 1) 51 52 i := len(dictionary) 53 a := append(dictionary, "test") 54 b, err := json.Marshal(&a) 55 if err != nil { 56 t.Error(err) 57 } 58 59 err = Write(string(b)) 60 if err != nil { 61 t.Error(err) 62 } 63 64 if i+1 != len(dictionary) { 65 t.Errorf("Before and after len don't match: %d+1.(before) != %d.(after)", i, len(dictionary)) 66 } 67 }