perkeep/lib/go/schema/schema_test.go

58 lines
1.1 KiB
Go
Raw Normal View History

2010-12-30 18:17:47 +00:00
package schema
import (
"strings"
"testing"
)
type isUtf8Test struct {
s string
e bool
}
func TestIsUtf8(t *testing.T) {
tests := []isUtf8Test{
{"foo", true},
{"Straße", true},
{string([]uint8{65, 234, 234, 192, 23, 123}), false},
{string([]uint8{65, 97}), true},
}
for idx, test := range tests {
if isValidUtf8(test.s) != test.e {
t.Errorf("expected isutf8==%d for test index %d", test.e, idx)
}
}
}
const kExpectedHeader = `{"camliVersion"`
func TestJson(t *testing.T) {
2010-12-31 06:37:46 +00:00
m := newMapForFileName("schema_test.go")
2010-12-30 18:17:47 +00:00
json, err := MapToCamliJson(m)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
t.Logf("Got json: [%s]\n", json)
// TODO: test it parses back
if !strings.HasPrefix(json, kExpectedHeader) {
t.Errorf("JSON does't start with expected header.")
}
2010-12-31 06:37:46 +00:00
}
func TestRegularFile(t *testing.T) {
m, err := NewFileMap("schema_test.go", nil)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
json, err := MapToCamliJson(m)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
t.Logf("Got json for regular file: [%s]\n", json)
// TODO: test it parses back
2010-12-30 18:17:47 +00:00
}