fix test, add string unit test, refactor stack
All checks were successful
/ test (push) Successful in 56s

This commit is contained in:
Neemek 2025-10-22 20:20:47 +02:00
parent b95d2954ba
commit beaa325c7b
3 changed files with 37 additions and 20 deletions

View file

@ -36,7 +36,7 @@ func GetCompileTestData() map[string]CompileTestData {
return map[string]CompileTestData{
"constant_string": {
&Program{
[]string{},
[]Import{},
&BlockNode{
[]Node{
&AssignNode{
@ -64,7 +64,7 @@ func GetCompileTestData() map[string]CompileTestData {
},
"conditional_false": {
&Program{
[]string{},
[]Import{},
&BlockNode{
[]Node{
&AssignNode{
@ -113,7 +113,7 @@ func GetCompileTestData() map[string]CompileTestData {
},
"conditional_true": {
&Program{
[]string{},
[]Import{},
&BlockNode{
[]Node{
&AssignNode{
@ -162,7 +162,7 @@ func GetCompileTestData() map[string]CompileTestData {
},
"conditional_else_false": {
&Program{
[]string{},
[]Import{},
&BlockNode{
[]Node{
&AssignNode{
@ -224,7 +224,7 @@ func GetCompileTestData() map[string]CompileTestData {
},
"conditional_else_true": {
&Program{
[]string{},
[]Import{},
&BlockNode{
[]Node{
&AssignNode{
@ -286,7 +286,7 @@ func GetCompileTestData() map[string]CompileTestData {
},
"addition": {
&Program{
[]string{},
[]Import{},
&BlockNode{
[]Node{
&AssignNode{
@ -321,7 +321,7 @@ func GetCompileTestData() map[string]CompileTestData {
},
"sum_function": {
&Program{
[]string{},
[]Import{},
&BlockNode{
[]Node{
&AssignNode{
@ -407,7 +407,7 @@ func GetCompileTestData() map[string]CompileTestData {
},
"remove_func_vars": {
&Program{
[]string{},
[]Import{},
&BlockNode{
[]Node{
&AssignNode{
@ -484,7 +484,7 @@ func GetCompileTestData() map[string]CompileTestData {
},
"two_lists": {
program: &Program{
[]string{},
[]Import{},
&BlockNode{
statements: []Node{
&AssignNode{
@ -536,7 +536,7 @@ func GetCompileTestData() map[string]CompileTestData {
},
"unary/negate": {
program: &Program{
[]string{},
[]Import{},
&BlockNode{
[]Node{
&AssignNode{
@ -566,7 +566,7 @@ func GetCompileTestData() map[string]CompileTestData {
},
"unary/not": {
program: &Program{
[]string{},
[]Import{},
&BlockNode{
[]Node{
&AssignNode{

View file

@ -17,18 +17,23 @@ func NewStack[T any](capacity Pos) *Stack[T] {
func (s *Stack[T]) Push(items ...T) {
for _, item := range items {
if s.Current >= s.Capacity {
panic("stack overflow")
}
if int(s.Current) == len(s.items) {
s.items = append(s.items, item)
}
s.items[s.Current] = item
s.Current++
s.pushItem(item)
}
}
func (s *Stack[T]) pushItem(item T) {
if s.Current >= s.Capacity {
panic("stack overflow")
}
if int(s.Current) == len(s.items) {
s.items = append(s.items, item)
} else {
s.items[s.Current] = item
}
s.Current++
}
func (s *Stack[T]) Pop() T {
if s.Current <= 0 {
panic("stack underflow")

12
tests/strings.ang Normal file
View file

@ -0,0 +1,12 @@
txt := "Hello world!"
# string length
assertEq(txt.length(), 12)
# string split
assertEq(txt.split(" ").length(), 2)
# string indexing
assertEq(txt.at(1), "e")
assertEq(txt.at(6), "w")