File tree Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -12,8 +12,23 @@ type ParseResult struct {
1212 parseResult parser.ParseResult
1313}
1414
15- // ---- TODO useful for the playground
16- // func (*ParseResult) GetNeededVariables() map[string]ValueType {}
15+ // Returns a map from a variable's name to its type.
16+ //
17+ // doesn't include variables whose value is already defined within the script
18+ func (p ParseResult ) GetNeededVariables () map [string ]string {
19+ m := make (map [string ]string )
20+
21+ for _ , varDecl := range p .parseResult .Value .Vars {
22+ if varDecl .Name == nil || varDecl .Origin != nil {
23+ continue
24+ }
25+
26+ m [varDecl .Name .Name ] = varDecl .Type .Name
27+ }
28+
29+ return m
30+ }
31+
1732// func (*ParseResult) GetDiagnostics() []Diagnostic {}
1833
1934type ParserError = parser.ParserError
Original file line number Diff line number Diff line change @@ -11,6 +11,30 @@ import (
1111 "github.com/stretchr/testify/require"
1212)
1313
14+ func TestGetVars (t * testing.T ) {
15+ parseResult := numscript .Parse (`
16+ vars {
17+ monetary $mon
18+ account $acc
19+ account $acc2
20+
21+ monetary $do_not_include_in_output = balance(@acc, USD/2)
22+ }
23+ ` )
24+
25+ require .Empty (t , parseResult .GetParsingErrors (), "There should not be parsing errors" )
26+
27+ require .Equal (t ,
28+ map [string ]string {
29+ "mon" : "monetary" ,
30+ "acc" : "account" ,
31+ "acc2" : "account" ,
32+ },
33+ parseResult .GetNeededVariables (),
34+ )
35+
36+ }
37+
1438func TestDoNotGetWorldBalance (t * testing.T ) {
1539 parseResult := numscript .Parse (`send [COIN 100] (
1640 source = @world
You can’t perform that action at this time.
0 commit comments