Skip to content

Commit

Permalink
add more testing for method call for integer, string, float
Browse files Browse the repository at this point in the history
  • Loading branch information
gravataLonga committed Jul 3, 2022
1 parent 29152eb commit 7ab17d9
Show file tree
Hide file tree
Showing 10 changed files with 374 additions and 200 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ brew install ninja-lang
To enable, add the following file `/etc/yum.repos.d/fury.repo`:

```sh
[fury]
name=Gemfury Private Repo
[ninja]
name=Ninja Programming Language
baseurl=https://yum.fury.io/gravatalonga/
enabled=1
gpgcheck=0
Expand All @@ -30,7 +30,7 @@ gpgcheck=0
Check if correctly created

```
yum --disablerepo=* --enablerepo=fury list available
yum --disablerepo=* --enablerepo=ninja list available
```

To install you only need run following command:
Expand All @@ -50,7 +50,7 @@ deb [trusted=yes] https://apt.fury.io/gravatalonga/ /
Or use this one line command:

```
echo "deb [trusted=yes] https://apt.fury.io/gravatalonga/ /" > /etc/apt/sources.list.d/fury.list
echo "deb [trusted=yes] https://apt.fury.io/gravatalonga/ /" > /etc/apt/sources.list.d/ninja.list
```

and them you can install
Expand Down
41 changes: 37 additions & 4 deletions evaluator/boolean_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func TestEvalBooleanExpression(t *testing.T) {
evaluated := testEval(tt.input, t)
testBooleanObject(t, evaluated, tt.expected)
})

}
}

Expand Down Expand Up @@ -173,11 +172,45 @@ func TestBooleanMethod(t *testing.T) {
`true.type()`,
"BOOLEAN",
},
{
`var a = false; a.type()`,
"BOOLEAN",
},
}

for _, tt := range tests {
evaluated := testEval(tt.input, t)
for i, tt := range tests {
t.Run(fmt.Sprintf("TestBooleanMethod[%d]", i), func(t *testing.T) {
evaluated := testEval(tt.input, t)

testObjectLiteral(t, evaluated, tt.expected)
})
}
}

testObjectLiteral(t, evaluated, tt.expected)
func TestBooleanWrongMethod(t *testing.T) {

tests := []struct {
input string
expectedErrorMessage interface{}
}{
{
`true.type(1)`,
"TypeError: bool.type() takes exactly 0 argument (1 given)",
},
}

for i, tt := range tests {
t.Run(fmt.Sprintf("TestBooleanMethod[%d]", i), func(t *testing.T) {
evaluated := testEval(tt.input, t)

errObj, ok := evaluated.(*object.Error)
if !ok {
t.Fatalf("no error object returned. got=%T(%+v)", evaluated, evaluated)
}

if errObj.Message != tt.expectedErrorMessage {
t.Errorf("erro expected \"%s\". Got: %s", tt.expectedErrorMessage, errObj.Message)
}
})
}
}
1 change: 0 additions & 1 deletion evaluator/digit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,5 @@ func TestEvalDigitExpression(t *testing.T) {
evaluated := testEval(tt.input, t)
testObjectLiteral(t, evaluated, tt.expected)
})

}
}
8 changes: 4 additions & 4 deletions evaluator/float_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,19 @@ func TestFloatMethodWrongUsage(t *testing.T) {
}{
{
`1.1.type(1)`,
"method type not accept any arguments. got: [1]",
"TypeError: float.type() takes exactly 0 argument (1 given)",
},
{
`1.1.string(1)`,
"method string not accept any arguments. got: [1]",
"TypeError: float.string() takes exactly 0 argument (1 given)",
},
{
`1.1.abs(1)`,
"method abs not accept any arguments. got: [1]",
"TypeError: float.abs() takes exactly 0 argument (1 given)",
},
{
`1.1.round(1)`,
"method round not accept any arguments. got: [1]",
"TypeError: float.round() takes exactly 0 argument (1 given)",
},
}

Expand Down
10 changes: 4 additions & 6 deletions evaluator/integer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,8 @@ func TestIntegerMethod(t *testing.T) {
for _, tt := range tests {
t.Run(fmt.Sprintf("TestIntegerMethod_%s", tt.input), func(t *testing.T) {
evaluated := testEval(tt.input, t)

testObjectLiteral(t, evaluated, tt.expected)
})

}
}

Expand All @@ -138,19 +136,19 @@ func TestIntegerMethodWrongUsage(t *testing.T) {
}{
{
`1.type(1)`,
"method type not accept any arguments. got: [1]",
"TypeError: int.type() takes exactly 0 argument (1 given)",
},
{
`1.string(1)`,
"method string not accept any arguments. got: [1]",
"TypeError: int.string() takes exactly 0 argument (1 given)",
},
{
`1.float(1)`,
"method float not accept any arguments. got: [1]",
"TypeError: int.float() takes exactly 0 argument (1 given)",
},
{
`1.abs(1)`,
"method abs not accept any arguments. got: [1]",
"TypeError: int.abs() takes exactly 0 argument (1 given)",
},
}

Expand Down
Loading

0 comments on commit 7ab17d9

Please sign in to comment.