Files
numscript/internal/parser/ast_test.go
Alessandro ScandoneandGitHub b8375d9483 Implement a "/" operator (#39)
* 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
2025-02-21 16:06:07 +01:00

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())
}