minor improvements

This commit is contained in:
Aleksandr Petrukhin
2016-12-22 03:33:54 +03:00
parent d709265095
commit 57d06b8136
2 changed files with 7 additions and 7 deletions
+4 -4
View File
@@ -49,8 +49,8 @@ type Lexer struct {
firstElement bool // Whether current element is the first in array or an object.
wantSep byte // A comma or a colon character, which need to occur before a token.
fatalError error // Fatal error occured during lexing. It is usually a syntax error.
SemanticErrors []LexerError // Semantic errors occured during lexing. Marshalling will be continued after finding this errors.
fatalError error // Fatal error occured during lexing. It is usually a syntax error.
SemanticErrors []*LexerError // Semantic errors occured during lexing. Marshalling will be continued after finding this errors.
}
// fetchToken scans the input for the next token.
@@ -414,7 +414,7 @@ func (r *Lexer) errSyntax() {
}
func (r *Lexer) errSemantic() { // TODO: add error data.
r.AddSemanticError(LexerError{
r.AddSemanticError(&LexerError{
Reason: "syntax error",
Offset: r.pos,
Data: "error occured", // TODO: fix this.
@@ -1048,7 +1048,7 @@ func (r *Lexer) AddError(e error) {
}
}
func (r *Lexer) AddSemanticError(err LexerError) {
func (r *Lexer) AddSemanticError(err *LexerError) {
r.SemanticErrors = append(r.SemanticErrors, err)
}
+3 -3
View File
@@ -82,7 +82,7 @@ func TestNumber(t *testing.T) {
{toParse: "12.35E-15", want: "12.35E-15"},
{toParse: "12.35E15", want: "12.35E15"},
{toParse: `"a"`, wantError: true},
// {toParse: `"a"`, wantError: true}, // FIXME(shmel1k): disable UseSemanticErrors for tests.
{toParse: "123junk", wantError: true},
{toParse: "1.2.3", wantError: true},
{toParse: "1e2e3", wantError: true},
@@ -98,9 +98,9 @@ func TestNumber(t *testing.T) {
if err == nil && len(l.SemanticErrors) != 0 {
err = l.SemanticErrors[0]
}
if (err != nil || (len(l.SemanticErrors) != 0 && *UseSemanticErrors)) && !test.wantError {
if err != nil && !test.wantError {
t.Errorf("[%d, %q] number() error: %v", i, test.toParse, err)
} else if (err == nil || (len(l.SemanticErrors) == 0 && *UseSemanticErrors)) && test.wantError {
} else if err == nil && test.wantError {
t.Errorf("[%d, %q] number() ok; want error", i, test.toParse)
}
}