mirror of
https://github.com/fluencelabs/aqua.git
synced 2024-12-04 06:30:17 +00:00
add tests
This commit is contained in:
parent
4f94de8efe
commit
6a3dd53b6b
@ -1,3 +1,3 @@
|
||||
func z() -> string:
|
||||
arr = nil
|
||||
arr = []
|
||||
<- arr!
|
@ -1,7 +1,7 @@
|
||||
package aqua.semantics
|
||||
|
||||
import aqua.parser.expr.func.ArrowExpr
|
||||
import aqua.parser.lexer.{BasicTypeToken, Name}
|
||||
import aqua.parser.lexer.BasicTypeToken
|
||||
import aqua.raw.Raw
|
||||
import aqua.raw.arrow.ArrowRaw
|
||||
import aqua.raw.ops.*
|
||||
@ -12,20 +12,17 @@ import aqua.types.*
|
||||
import aqua.types.ScalarType.*
|
||||
|
||||
import cats.Id
|
||||
import cats.syntax.applicative.*
|
||||
import cats.data.{NonEmptyList, NonEmptyMap, State}
|
||||
import org.scalatest.EitherValues
|
||||
import cats.syntax.applicative.*
|
||||
import org.scalatest.{EitherValues, Inside}
|
||||
import org.scalatest.flatspec.AnyFlatSpec
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.Inside
|
||||
|
||||
class ArrowSemSpec extends AnyFlatSpec with Matchers with EitherValues with Inside {
|
||||
|
||||
import Utils.{given, *}
|
||||
import Utils.{*, given}
|
||||
|
||||
def program(arrowStr: String): Prog[State[CompilerState[cats.Id], *], Raw] = {
|
||||
import CompilerState.*
|
||||
|
||||
val expr = ArrowExpr.p.parseAll(arrowStr).value.mapK(spanToId)
|
||||
val sem = new ArrowSem[Id](expr)
|
||||
|
||||
|
@ -0,0 +1,48 @@
|
||||
package aqua.semantics
|
||||
|
||||
import aqua.parser.expr.func.{AssignmentExpr, ClosureExpr}
|
||||
import aqua.parser.lexer.CollectionToken.Mode.ArrayMode
|
||||
import aqua.parser.lexer.{CollectionToken, Name, VarToken}
|
||||
import aqua.parser.lift.Span
|
||||
import aqua.raw.Raw
|
||||
import aqua.semantics.expr.func.{AssignmentSem, ClosureSem}
|
||||
|
||||
import cats.Id
|
||||
import cats.data.State
|
||||
import org.scalatest.Inside
|
||||
import org.scalatest.flatspec.AnyFlatSpec
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
|
||||
class AssignmentSemSpec extends AnyFlatSpec with Matchers with Inside {
|
||||
|
||||
import Utils.{*, given}
|
||||
|
||||
val program: Prog[State[CompilerState[cats.Id], *], Raw] = {
|
||||
val expr = ClosureExpr(Name[Id]("closure"), None)
|
||||
val sem = new ClosureSem[Id](expr)
|
||||
|
||||
sem.program[State[CompilerState[Id], *]]
|
||||
}
|
||||
|
||||
"it" should "throw an error on 'nil'" in {
|
||||
val expr = AssignmentExpr(Name[Id]("emptyArr"), VarToken[Id](Name[Id]("nil")))
|
||||
val sem = new AssignmentSem[Id](expr)
|
||||
|
||||
val state = getState(sem.program[State[CompilerState[Id], *]])
|
||||
|
||||
inside(state.errors) { errors =>
|
||||
atLeast(1, errors.toList) shouldBe a[RulesViolated[Span.S]]
|
||||
}
|
||||
}
|
||||
|
||||
"it" should "throw an error on empty array" in {
|
||||
val expr = AssignmentExpr(Name[Id]("emptyArr"), CollectionToken[Id](ArrayMode, Nil))
|
||||
val sem = new AssignmentSem[Id](expr)
|
||||
|
||||
val state = getState(sem.program[State[CompilerState[Id], *]])
|
||||
|
||||
inside(state.errors) { errors =>
|
||||
atLeast(1, errors.toList) shouldBe a[RulesViolated[Span.S]]
|
||||
}
|
||||
}
|
||||
}
|
@ -1,38 +1,24 @@
|
||||
package aqua.semantics
|
||||
|
||||
import aqua.parser.expr.func.ClosureExpr
|
||||
import aqua.parser.lexer.{Name, Token}
|
||||
import aqua.raw.arrow.ArrowRaw
|
||||
import aqua.parser.lexer.Name
|
||||
import aqua.raw.Raw
|
||||
import aqua.raw.ops.{EmptyTag, FuncOp, RawTag}
|
||||
import aqua.raw.arrow.ArrowRaw
|
||||
import aqua.raw.ops.RawTag
|
||||
import aqua.semantics.expr.func.ClosureSem
|
||||
import aqua.semantics.rules.names.{NamesInterpreter, NamesState}
|
||||
import aqua.types.{ArrowType, ProductType}
|
||||
|
||||
import cats.Id
|
||||
import cats.data.*
|
||||
import cats.data.State.*
|
||||
import cats.instances.all.*
|
||||
import cats.syntax.all.*
|
||||
import cats.syntax.applicative.*
|
||||
import cats.syntax.apply.*
|
||||
import cats.syntax.bifunctor.*
|
||||
import cats.syntax.comonad.*
|
||||
import cats.syntax.flatMap.*
|
||||
import cats.syntax.functor.*
|
||||
import cats.syntax.monad.*
|
||||
import cats.syntax.semigroup.*
|
||||
import cats.{catsInstancesForId, Id, Monad}
|
||||
import monocle.Lens
|
||||
import monocle.macros.GenLens
|
||||
import monocle.syntax.all.*
|
||||
import org.scalatest.flatspec.AnyFlatSpec
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
|
||||
class ClosureSemSpec extends AnyFlatSpec with Matchers {
|
||||
|
||||
import Utils.{given, *}
|
||||
import Utils.{*, given}
|
||||
|
||||
val program: Prog[State[CompilerState[cats.Id], *], Raw] = {
|
||||
import CompilerState.*
|
||||
val expr = ClosureExpr(Name[Id]("closure"), None)
|
||||
val sem = new ClosureSem[Id](expr)
|
||||
|
||||
|
@ -5,14 +5,13 @@ import aqua.parser.lexer.{Ability, Name}
|
||||
import aqua.raw.RawContext
|
||||
import aqua.raw.arrow.{ArrowRaw, FuncRaw}
|
||||
import aqua.raw.ops.RawTag
|
||||
import aqua.raw.value.VarRaw
|
||||
import aqua.semantics.header.{HeaderHandler, HeaderSem}
|
||||
import aqua.types.{AbilityType, ArrowType, NilType, ProductType, ScalarType}
|
||||
import aqua.types.*
|
||||
|
||||
import cats.data.{Chain, NonEmptyList, NonEmptyMap, Validated}
|
||||
import cats.free.Cofree
|
||||
import cats.{Eval, Id, Monoid}
|
||||
import cats.syntax.applicative.*
|
||||
import cats.{Eval, Id, Monoid}
|
||||
import org.scalatest.Inside
|
||||
import org.scalatest.flatspec.AnyFlatSpec
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
|
@ -1,26 +1,19 @@
|
||||
package aqua.semantics
|
||||
|
||||
import aqua.raw.RawContext
|
||||
import aqua.parser.Ast
|
||||
import aqua.raw.ops.{Call, CallArrowRawTag, FuncOp, OnTag, ParTag, RawTag, SeqGroupTag, SeqTag}
|
||||
import aqua.parser.Parser
|
||||
import aqua.parser.{Ast, Parser}
|
||||
import aqua.parser.lift.{LiftParser, Span}
|
||||
import aqua.raw.RawContext
|
||||
import aqua.raw.ops.*
|
||||
import aqua.raw.value.*
|
||||
import aqua.types.*
|
||||
import aqua.raw.ops.*
|
||||
|
||||
import cats.Eval
|
||||
import cats.data.{Chain, EitherNec, NonEmptyChain, Validated}
|
||||
import cats.free.Cofree
|
||||
import cats.syntax.foldable.*
|
||||
import org.scalatest.Inside
|
||||
import org.scalatest.flatspec.AnyFlatSpec
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.Inside
|
||||
import cats.~>
|
||||
import cats.data.{Chain, EitherNec, NonEmptyChain}
|
||||
import cats.syntax.show.*
|
||||
import cats.syntax.traverse.*
|
||||
import cats.syntax.foldable.*
|
||||
import cats.data.Validated
|
||||
import cats.free.Cofree
|
||||
import cats.data.State
|
||||
import cats.Eval
|
||||
|
||||
class SemanticsSpec extends AnyFlatSpec with Matchers with Inside {
|
||||
|
||||
|
@ -1,23 +1,17 @@
|
||||
package aqua.semantics
|
||||
|
||||
import aqua.parser.expr.func.ClosureExpr
|
||||
import aqua.parser.lexer.{Name, Token}
|
||||
import aqua.parser.lift.Span
|
||||
import aqua.raw.{Raw, RawContext}
|
||||
import aqua.semantics.expr.func.ClosureSem
|
||||
import aqua.semantics.rules.abilities.{AbilitiesAlgebra, AbilitiesInterpreter, AbilitiesState}
|
||||
import aqua.semantics.rules.abilities.{AbilitiesAlgebra, AbilitiesInterpreter}
|
||||
import aqua.semantics.rules.locations.{DummyLocationsInterpreter, LocationsAlgebra}
|
||||
import aqua.semantics.rules.names.{NamesAlgebra, NamesInterpreter, NamesState}
|
||||
import aqua.semantics.rules.types.{TypesAlgebra, TypesInterpreter, TypesState}
|
||||
import aqua.semantics.rules.mangler.{ManglerAlgebra, ManglerInterpreter}
|
||||
import aqua.semantics.rules.names.{NamesAlgebra, NamesInterpreter}
|
||||
import aqua.semantics.rules.report.{ReportAlgebra, ReportInterpreter}
|
||||
import aqua.semantics.rules.types.{TypesAlgebra, TypesInterpreter}
|
||||
import aqua.types.*
|
||||
|
||||
import cats.data.State
|
||||
import cats.{~>, Id}
|
||||
import monocle.Lens
|
||||
import monocle.macros.GenLens
|
||||
import monocle.syntax.all.*
|
||||
import cats.{Id, ~>}
|
||||
|
||||
object Utils {
|
||||
|
||||
@ -50,6 +44,10 @@ object Utils {
|
||||
prog.apply(emptyS).run(blankCS).value._2
|
||||
}
|
||||
|
||||
def getState(prog: Prog[State[CompilerState[cats.Id], *], Raw]): CompilerState[Id] = {
|
||||
prog.apply(emptyS).run(blankCS).value._1
|
||||
}
|
||||
|
||||
def getState(
|
||||
startState: Raw
|
||||
)(prog: Prog[State[CompilerState[cats.Id], *], Raw]): CompilerState[Id] = {
|
||||
|
@ -12,6 +12,7 @@ import aqua.semantics.rules.names.{NamesAlgebra, NamesInterpreter, NamesState}
|
||||
import aqua.semantics.rules.report.{ReportAlgebra, ReportInterpreter}
|
||||
import aqua.semantics.rules.types.{TypesAlgebra, TypesInterpreter}
|
||||
import aqua.types.*
|
||||
|
||||
import cats.Id
|
||||
import cats.data.{NonEmptyList, NonEmptyMap, State}
|
||||
import monocle.syntax.all.*
|
||||
|
Loading…
Reference in New Issue
Block a user