Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for parser #164

Merged
merged 8 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions pkg/yang/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ func (s *Statement) SubStatements() []*Statement { return s.statements }

// String returns s's tree as a string.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best just to remove this given that it doesn't seem like it does anything particularly useful? Or is this part of the interface that needs to be implemented?

If it's not, should we create some simple implementation here (YANG statement at line X, or even. just <YANG Statement>)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll delete this since it doesn't seem to be need by anything else in goyang as well as ygot.

If someone complains I will add an implementation for it. Added tracking bug at #193

func (s *Statement) String() string {
var b bytes.Buffer
s.Write(&b, "")
return b.String()
// XXX: Unimplemented
return ""
}

// Location returns the location in the source where s was defined.
Expand Down Expand Up @@ -319,7 +318,7 @@ func (p *parser) nextStatement() *Statement {
}
}
default:
fmt.Fprintf(p.errout, "%v: syntax error, expected ';' or nested statements in {}\n", t)
fmt.Fprintf(p.errout, "%v: syntax error, expected ';' or '{'\n", t)
return ignoreMe
}
}
Expand Down
110 changes: 109 additions & 1 deletion pkg/yang/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,114 @@ pattern '\\ \S \n';
},
},
{line: line(), in: `
foo "bar" + "baz";
`,
out: []*Statement{
SA("foo", "barbaz"),
},
},
{line: line(), in: `
foo "bar" + "+" + "baz";
`,
out: []*Statement{
SA("foo", "bar+baz"),
},
},
{line: line(), in: `
foo "bar"
`,
err: `test.yang: unexpected EOF`,
},
{line: line(), in: `
foo "bar" + "baz"
`,
err: `test.yang: unexpected EOF`,
},
{line: line(), in: `
foo "bar" baz;
`,
err: `test.yang:2:11: baz: syntax error, expected ';' or '{'
test.yang:2:14: ;: keyword token not an unquoted string`,
},
{line: line(), in: `
foo "bar" + baz;
`,
err: `test.yang:2:11: +: syntax error, expected ';' or '{'`,
},
{line: line(), in: `
foo "bar" +
`,
err: `test.yang:2:11: +: syntax error, expected ';' or '{'`,
},
{line: line(), in: `
foo "bar";
`,
out: []*Statement{
SA("foo", "bar"),
},
},
{line: line(), in: `
foo "bar" {}
`,
out: []*Statement{
SA("foo", "bar"),
},
},
{line: line(), in: `
foo 'bar' + 'baz';
`,
out: []*Statement{
SA("foo", "barbaz"),
},
},
{line: line(), in: `
foo 'bar' + '+' + 'baz';
`,
out: []*Statement{
SA("foo", "bar+baz"),
},
},
{line: line(), in: `
foo 'bar'
`,
err: `test.yang: unexpected EOF`,
},
{line: line(), in: `
foo 'bar' + 'baz'
`,
err: `test.yang: unexpected EOF`,
},
{line: line(), in: `
foo 'bar' baz;
`,
err: `test.yang:2:11: baz: syntax error, expected ';' or '{'
test.yang:2:14: ;: keyword token not an unquoted string`,
},
{line: line(), in: `
foo 'bar' + baz;
`,
err: `test.yang:2:11: +: syntax error, expected ';' or '{'`,
},
{line: line(), in: `
foo 'bar' +
`,
err: `test.yang:2:11: +: syntax error, expected ';' or '{'`,
},
{line: line(), in: `
foo 'bar';
`,
out: []*Statement{
SA("foo", "bar"),
},
},
{line: line(), in: `
foo 'bar' {}
`,
out: []*Statement{
SA("foo", "bar"),
},
},
{line: line(), in: `
foo bar;
red black;
`,
Expand Down Expand Up @@ -239,7 +347,7 @@ id
{line: line(), in: `
statement one two { }
`,
err: `test.yang:2:15: two: syntax error, expected ';' or nested statements in {}
err: `test.yang:2:15: two: syntax error, expected ';' or '{'
test.yang:2:19: {: keyword token not an unquoted string
test.yang:2:21: unexpected }`,
},
Expand Down