Skip to content

Commit

Permalink
New unit test for lexicon
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuznet committed Mar 29, 2024
1 parent 0658fed commit 90f9cbe
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lexicon/lexicon_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package lexicon

import (
"regexp"
"testing"
)

func initLexicon() {
LexiconPatterns = make(map[string]LexiconPattern)
lex := Lexicon{
Name: "did", Patterns: []string{".*unittest.*"}, Length: 100,
}
var patterns []*regexp.Regexp
for _, pat := range lex.Patterns {
patterns = append(patterns, regexp.MustCompile(pat))
}
lexPattern := LexiconPattern{
Lexicon: lex,
Patterns: patterns,
}
LexiconPatterns["did"] = lexPattern
}

// TestPatterns
func TestPatterns(t *testing.T) {
if LexiconPatterns == nil {
initLexicon()
}
err := CheckPattern("did", "xyz")
if err == nil {
t.Error("unable to correct match did pattern")
}
err = CheckPattern("did", "unittest")
if err != nil {
t.Error(err)
}
}

0 comments on commit 90f9cbe

Please sign in to comment.