Skip to content

Commit

Permalink
Added another FileParser test
Browse files Browse the repository at this point in the history
  • Loading branch information
RealA10N committed Aug 3, 2024
1 parent 8485195 commit 8849a16
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion parse/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// TODO: this should be a tagged union.
// The supported caller arguments are registers, globals, immediates (and labales?)
// The supported caller arguments are registers, globals, immediates (and labels?)

type ArgumentNode struct {
source.UnmanagedSourceView
Expand Down
27 changes: 27 additions & 0 deletions parse/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/assert"
)

// The purpose of the test is to verify the structure of "simple" source file.
func TestSingleFunction(t *testing.T) {
src := `def $i32 @add $i32 %x $i32 %y {
%res = add %x %y
Expand Down Expand Up @@ -72,3 +73,29 @@ func TestSingleFunction(t *testing.T) {
assert.Nil(t, perr)
assert.Equal(t, expected, file)
}

func TestFileParserTwoFunctionsNoExtraSeparator(t *testing.T) {
src := `def @first {
}
def @second {
}`

expected := `def @first {
}
def @second {
}
`

v := source.NewSourceView(src)
_, ctx := v.Detach()
tkns, err := lex.NewTokenizer().Tokenize(v)
assert.NoError(t, err)

tknsView := parse.NewTokenView(tkns)
file, perr := parse.FileParser{}.Parse(&tknsView)
assert.Nil(t, perr)

got := file.String(ctx)
assert.Equal(t, expected, got)
}

0 comments on commit 8849a16

Please sign in to comment.