mirror of
https://github.com/hanzoai/numscript.git
synced 2026-10-30 18:26:57 +00:00
* feat: edited the antlr grammar, updated the AST, the parser and its snapshots * fix: updated percentageLiteral.ToRatio() method * feat: implemented "/" operator in interpreter * test: added test with variable numerator and denominator * feat: implemented static type analysis of "/" expressions * chore: fix indentation * refactor: change ast node definition * feat: improve static analysis in allotment * feat: implemented hover for div operator * feat: better diagnostic description * chore: removed unused comment * refactor: renamed file * fix: handle divide by zero runtime err * fix: check div by zero in diagnostics * test: added test * test: add static analysis test with perc literal * test: add op precedence snap test
27 lines
608 B
Go
27 lines
608 B
Go
package parser_test
|
|
|
|
import (
|
|
"math/big"
|
|
"testing"
|
|
|
|
"github.com/formancehq/numscript/internal/parser"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestPercentageLiteralToRatio(t *testing.T) {
|
|
assert.Equal(t, big.NewRat(123, 100), parser.PercentageLiteral{
|
|
Amount: big.NewInt(123),
|
|
FloatingDigits: 0,
|
|
}.ToRatio())
|
|
|
|
assert.Equal(t, big.NewRat(123, 1000), parser.PercentageLiteral{
|
|
Amount: big.NewInt(123),
|
|
FloatingDigits: 1,
|
|
}.ToRatio())
|
|
|
|
assert.Equal(t, big.NewRat(123, 10000), parser.PercentageLiteral{
|
|
Amount: big.NewInt(123),
|
|
FloatingDigits: 2,
|
|
}.ToRatio())
|
|
}
|