Skip to content

Commit

Permalink
Add invalid alias test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
RZhang05 committed Dec 17, 2024
1 parent 76a2aec commit 5689128
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions sema/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ func TestCheckImportAlias(t *testing.T) {
require.NoError(t, err)
})

t.Run("valid, multiple alias of same contract", func(t *testing.T) {
t.Run("valid multiple alias of same contract", func(t *testing.T) {

importedChecker, err := ParseAndCheckWithOptions(t,
`
Expand Down Expand Up @@ -926,7 +926,7 @@ func TestCheckImportAlias(t *testing.T) {
require.NoError(t, err)
})

t.Run("invalid, duplicate aliases", func(t *testing.T) {
t.Run("invalid duplicate aliases", func(t *testing.T) {

importedChecker, err := ParseAndCheckWithOptions(t,
`
Expand Down Expand Up @@ -1015,4 +1015,46 @@ func TestCheckImportAlias(t *testing.T) {

})

t.Run("invalid use orig instead of alias", func(t *testing.T) {

importedChecker, err := ParseAndCheckWithOptions(t,
`
access(all) fun a(): Int {
return 42
}
`,
ParseAndCheckOptions{
Location: ImportedLocation,
},
)

require.NoError(t, err)

_, err = ParseAndCheckWithOptions(t,
`
import a as b from "imported"
access(all) fun main() {
a()
}
`,
ParseAndCheckOptions{
Config: &sema.Config{
ImportHandler: func(_ *sema.Checker, _ common.Location, _ ast.Range) (sema.Import, error) {
return sema.ElaborationImport{
Elaboration: importedChecker.Elaboration,
}, nil
},
},
},
)

errs := RequireCheckerErrors(t, err, 1)

notDeclaredError := &sema.NotDeclaredError{}
assert.ErrorAs(t, errs[0], &notDeclaredError)

})

}

0 comments on commit 5689128

Please sign in to comment.