MCPcopy
hub / github.com/google/mangle / TestParsePackage

Function TestParsePackage

parse/parse_test.go:226–260  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

224}
225
226func TestParsePackage(t *testing.T) {
227 tests := []struct {
228 name string
229 str string
230 want []ast.Decl
231 }{
232 {
233 name: "Regular package",
234 str: "Package foo.bar!",
235 want: []ast.Decl{makeDecl(t, ast.NewAtom("Package"), []ast.Atom{ast.NewAtom("name", ast.String("foo.bar"))}, nil, nil)},
236 },
237 {
238 name: "White space allowed after identifier",
239 str: "Package foo.bar !",
240 want: []ast.Decl{makeDecl(t, ast.NewAtom("Package"), []ast.Atom{ast.NewAtom("name", ast.String("foo.bar"))}, nil, nil)},
241 },
242 {
243 name: "Package with atoms",
244 str: `Package foo [atom1("hello"), atom2()]!`,
245 want: []ast.Decl{makeDecl(t, ast.NewAtom("Package"), []ast.Atom{ast.NewAtom("name", ast.String("foo")), ast.NewAtom("atom1", ast.String("hello")), ast.NewAtom("atom2")}, nil, nil)},
246 },
247 }
248 for _, test := range tests {
249 t.Run(test.name, func(t *testing.T) {
250 got, err := Unit(strings.NewReader(test.str))
251 if err != nil {
252 t.Fatalf("Unit(%v) failed with %v", test.str, err)
253 }
254 if diff := cmp.Diff(test.want, got.Decls, cmp.Comparer(equals)); diff != "" {
255 t.Errorf("Unit(%v) = %v want %v diff %v", test.str, got, test.want, diff)
256 }
257 })
258 }
259
260}
261
262func TestParsePackageError(t *testing.T) {
263 tests := []struct {

Callers

nothing calls this directly

Calls 4

NewAtomFunction · 0.92
StringFunction · 0.92
UnitFunction · 0.85
makeDeclFunction · 0.70

Tested by

no test coverage detected