Changed the delimiter between scope name and variable name to underscore and updated tests
This commit is contained in:
parent
8b4c7dc0d4
commit
495aaeb6c0
2 changed files with 13 additions and 13 deletions
|
|
@ -50,14 +50,14 @@ func (s *Symbol) IsWord() bool { return s.Has(FlagWord) }
|
||||||
func (s *Symbol) IsConst() bool { return s.Has(FlagConst) }
|
func (s *Symbol) IsConst() bool { return s.Has(FlagConst) }
|
||||||
func (s *Symbol) IsAbsolute() bool { return s.Has(FlagAbsolute) }
|
func (s *Symbol) IsAbsolute() bool { return s.Has(FlagAbsolute) }
|
||||||
func (s *Symbol) IsZeroPage() bool { return s.Has(FlagZeroPage) }
|
func (s *Symbol) IsZeroPage() bool { return s.Has(FlagZeroPage) }
|
||||||
func (s *Symbol) IsZeroPagePointer() bool { return s.HasAll(FlagAbsolute | FlagZeroPage) }
|
func (s *Symbol) IsZeroPagePointer() bool { return s.HasAll(FlagAbsolute | FlagZeroPage | FlagWord) }
|
||||||
|
|
||||||
// FullName returns the fully qualified name (scope.name or just name)
|
// FullName returns the fully qualified name (scope.name or just name)
|
||||||
func (s *Symbol) FullName() string {
|
func (s *Symbol) FullName() string {
|
||||||
if s.Scope == "" {
|
if s.Scope == "" {
|
||||||
return s.Name
|
return s.Name
|
||||||
}
|
}
|
||||||
return s.Scope + "." + s.Name
|
return s.Scope + "_" + s.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
// SymbolTable manages variable and constant declarations
|
// SymbolTable manages variable and constant declarations
|
||||||
|
|
|
||||||
|
|
@ -88,8 +88,8 @@ func TestSymbolFullName(t *testing.T) {
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{"global", "counter", "", "counter"},
|
{"global", "counter", "", "counter"},
|
||||||
{"local", "temp", "main", "main.temp"},
|
{"local", "temp", "main", "main_temp"},
|
||||||
{"nested", "var", "outer.inner", "outer.inner.var"},
|
{"nested", "var", "outer_inner", "outer_inner_var"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|
@ -275,7 +275,7 @@ func TestLookup(t *testing.T) {
|
||||||
st.AddVar("local", "main", KindByte, 0)
|
st.AddVar("local", "main", KindByte, 0)
|
||||||
|
|
||||||
// Local in nested function
|
// Local in nested function
|
||||||
st.AddVar("inner", "main.helper", KindByte, 0)
|
st.AddVar("inner", "main_helper", KindByte, 0)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|
@ -303,21 +303,21 @@ func TestLookup(t *testing.T) {
|
||||||
searchName: "local",
|
searchName: "local",
|
||||||
currentScopes: []string{"main"},
|
currentScopes: []string{"main"},
|
||||||
expectFound: true,
|
expectFound: true,
|
||||||
expectFull: "main.local",
|
expectFull: "main_local",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "shadow global with local",
|
name: "shadow global with local",
|
||||||
searchName: "local",
|
searchName: "local",
|
||||||
currentScopes: []string{"main"},
|
currentScopes: []string{"main"},
|
||||||
expectFound: true,
|
expectFound: true,
|
||||||
expectFull: "main.local",
|
expectFull: "main_local",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "find inner from nested scope",
|
name: "find inner from nested scope",
|
||||||
searchName: "inner",
|
searchName: "inner",
|
||||||
currentScopes: []string{"main", "main.helper"},
|
currentScopes: []string{"main", "main_helper"},
|
||||||
expectFound: true,
|
expectFound: true,
|
||||||
expectFull: "main.helper.inner",
|
expectFull: "main_helper_inner",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "not found",
|
name: "not found",
|
||||||
|
|
@ -359,7 +359,7 @@ func TestExpandName(t *testing.T) {
|
||||||
currentScopes []string
|
currentScopes []string
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{"expand local", "local", []string{"main"}, "main.local"},
|
{"expand local", "local", []string{"main"}, "main_local"},
|
||||||
{"expand global", "global", []string{"main"}, "global"},
|
{"expand global", "global", []string{"main"}, "global"},
|
||||||
{"no expansion needed", "notfound", []string{}, "notfound"},
|
{"no expansion needed", "notfound", []string{}, "notfound"},
|
||||||
}
|
}
|
||||||
|
|
@ -648,7 +648,7 @@ func TestGenerateScopedVariables(t *testing.T) {
|
||||||
|
|
||||||
st.AddVar("global", "", KindByte, 0)
|
st.AddVar("global", "", KindByte, 0)
|
||||||
st.AddVar("local", "main", KindByte, 0)
|
st.AddVar("local", "main", KindByte, 0)
|
||||||
st.AddVar("nested", "main.helper", KindByte, 0)
|
st.AddVar("nested", "main_helper", KindByte, 0)
|
||||||
|
|
||||||
lines := GenerateVariables(st)
|
lines := GenerateVariables(st)
|
||||||
output := strings.Join(lines, "\n")
|
output := strings.Join(lines, "\n")
|
||||||
|
|
@ -657,10 +657,10 @@ func TestGenerateScopedVariables(t *testing.T) {
|
||||||
if !strings.Contains(output, "global\t!8") {
|
if !strings.Contains(output, "global\t!8") {
|
||||||
t.Error("expected global variable")
|
t.Error("expected global variable")
|
||||||
}
|
}
|
||||||
if !strings.Contains(output, "main.local\t!8") {
|
if !strings.Contains(output, "main_local\t!8") {
|
||||||
t.Error("expected scoped variable with full name")
|
t.Error("expected scoped variable with full name")
|
||||||
}
|
}
|
||||||
if !strings.Contains(output, "main.helper.nested\t!8") {
|
if !strings.Contains(output, "main_helper_nested\t!8") {
|
||||||
t.Error("expected nested scoped variable with full name")
|
t.Error("expected nested scoped variable with full name")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue