Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
hhatto committed Jul 15, 2024
1 parent fb8f0f7 commit f42734b
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,3 +528,47 @@ const color = "blue"
t.Errorf("invalid logic. lang=%v", clocFile.Lang)
}
}

func TestAnalayzeFile4Just(t *testing.T) {
tmpfile, err := os.CreateTemp("", "tmp.go")
if err != nil {
t.Logf("os.CreateTemp() error. err=[%v]", err)
return
}
defer os.Remove(tmpfile.Name())

if _, err := tmpfile.Write([]byte(`polyglot: python js perl sh ruby nu
python:
#!/usr/bin/env python3
print('Hello from python!')
js:
#!/usr/bin/env node
console.log('Greetings from JavaScript!') # with comment
# this is comment
`),
); err != nil {
t.Fatalf("tmpfile.Write() error. err=[%v]", err)
}

language := NewLanguage("Just", []string{"#"}, [][]string{{"", ""}}).
WithRegexLineComments([]string{`^#[^!].*`})
clocOpts := NewClocOptions()
clocFile := AnalyzeFile(tmpfile.Name(), language, clocOpts)
tmpfile.Close()

if clocFile.Blanks != 3 {
t.Errorf("invalid logic. blanks=%v", clocFile.Blanks)
}
if clocFile.Comments != 1 {
t.Errorf("invalid logic. comments=%v", clocFile.Comments)
}
if clocFile.Code != 7 {
t.Errorf("invalid logic. code=%v", clocFile.Code)
}
if clocFile.Lang != "Just" {
t.Errorf("invalid logic. lang=%v", clocFile.Lang)
}
}

0 comments on commit f42734b

Please sign in to comment.