-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👷 Split AST analysis into three phases
- Loading branch information
1 parent
cbc0440
commit 47ebc28
Showing
6 changed files
with
150 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,57 @@ | ||
package analyzer | ||
|
||
import "testing" | ||
import ( | ||
"solbot/parser" | ||
"solbot/symbols" | ||
"solbot/token" | ||
"testing" | ||
) | ||
|
||
func Test_PopulateSymbols(t *testing.T) { | ||
// testContractPath := "testdata/foundry/src/001_Counter.sol" | ||
func Test_PopulateSymbols_GetSymbolsByName(t *testing.T) { | ||
testContractPath := "testdata/foundry/src/002_SimpleCounter.sol" | ||
p := parser.Parser{} | ||
sourceFile, err := token.NewSourceFile(testContractPath, "") | ||
if err != nil { | ||
t.Fatalf("Could not create source file: %s", err) | ||
} | ||
|
||
p.Init(sourceFile) | ||
|
||
file := p.ParseFile() | ||
checkParserErrors(t, &p) | ||
|
||
if file == nil { | ||
t.Fatalf("ParseFile() returned nil") | ||
} | ||
|
||
env := symbols.NewEnvironment() | ||
discoverSymbols(file, env, nil) | ||
|
||
tests := []struct { | ||
expectedSymbolName string | ||
}{ | ||
{"increment"}, | ||
{"decrement"}, | ||
{"reset"}, | ||
} | ||
|
||
for _, tt := range tests { | ||
_, found := env.Get(tt.expectedSymbolName) | ||
if !found { | ||
t.Fatalf("Symbol: '%s' not found.", tt.expectedSymbolName) | ||
} | ||
} | ||
} | ||
|
||
func checkParserErrors(t *testing.T, p *parser.Parser) { | ||
errors := p.Errors() | ||
if len(errors) == 0 { | ||
return | ||
} | ||
|
||
t.Errorf("Parser has %d errors", len(errors)) | ||
for _, err := range errors { | ||
t.Errorf("Parser error: %s", err.Msg) | ||
} | ||
t.FailNow() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters