Skip to content

Pattern Matching #76

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion auxiliary.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,9 @@ func LoadFile(l *State, fileName, mode string) error {
if f != os.Stdin {
_ = f.Close()
}
if err != nil {
switch err {
case nil, SyntaxError, MemoryError: // do nothing
default:
l.SetTop(fileNameIndex)
return fileError("read")
}
Expand Down
39 changes: 39 additions & 0 deletions auxiliary_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package lua

import "testing"

func TestLoadFileSyntaxError(t *testing.T) {
l := NewState()
err := LoadFile(l, "fixtures/syntax_error.lua", "")
if err != SyntaxError {
t.Error("didn't return SyntaxError on file with syntax error")
}
if l.Top() != 1 {
t.Error("didn't push anything to the stack")
}
if l.IsString(-1) != true {
t.Error("didn't push a string to the stack")
}
estr, _ := l.ToString(-1)
if estr != "fixtures/syntax_error.lua:4: syntax error near <eof>" {
t.Error("didn't push the correct error string")
}
}

func TestLoadStringSyntaxError(t *testing.T) {
l := NewState()
err := LoadString(l, "this_is_a_syntax_error")
if err != SyntaxError {
t.Error("didn't return SyntaxError on string with syntax error")
}
if l.Top() != 1 {
t.Error("didn't push anything to the stack")
}
if l.IsString(-1) != true {
t.Error("didn't push a string to the stack")
}
estr, _ := l.ToString(-1)
if estr != "[string \"this_is_a_syntax_error\"]:1: syntax error near <eof>" {
t.Error("didn't push the correct error string")
}
}
3 changes: 3 additions & 0 deletions fixtures/syntax_error.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- A file that should generate a syntax error

this_is_a_syntax_error
Loading