Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework constant widgets #57

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Fabulous.AST.Tests/Expressions/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module App =

[<Test>]
let ``let value with a App expression`` () =
AnonymousModule() { Value("x", AppExpr("printfn") { ConstantExpr("\"a\"") }) }
AnonymousModule() { Value("x", AppExpr("printfn") { ConstantExpr(ConstantString "\"a\"") }) }
|> produces
"""

Expand Down
12 changes: 6 additions & 6 deletions src/Fabulous.AST.Tests/Expressions/ArrayOrList.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ module ArrayOrList =
Value(
"x",
ArrayExpr() {
ConstantExpr("1")
ConstantExpr("2")
ConstantExpr("3")
ConstantExpr(ConstantString "1")
ConstantExpr(ConstantString "2")
ConstantExpr(ConstantString "3")
}
)
}
Expand All @@ -33,9 +33,9 @@ let x = [| 1; 2; 3 |]
Value(
"x",
ListExpr() {
ConstantExpr("1")
ConstantExpr("2")
ConstantExpr("3")
ConstantExpr(ConstantString "1")
ConstantExpr(ConstantString "2")
ConstantExpr(ConstantString "3")
}
)
}
Expand Down
118 changes: 118 additions & 0 deletions src/Fabulous.AST.Tests/Expressions/Constant.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
namespace Fabulous.AST.Tests.Expressions

open NUnit.Framework
open Fabulous.AST.Tests

open Fabulous.AST

open type Ast

module Constant =

[<Test>]
let ``let value with a ConstantExpr expression with ConstantString`` () =
AnonymousModule() { Value("x", ConstantExpr(ConstantString "\"a\"")) }
|> produces
"""

let x = "a"
"""

[<Test>]
let ``let value with a ConstantExpr expression with ConstantMeasure`` () =
AnonymousModule() { Value("x", ConstantExpr(ConstantMeasure(ConstantString("1.0"), MeasureSingle("cm")))) }
|> produces
"""

let x = 1.0<cm>
"""

[<Test>]
let ``let value with a ConstantExpr expression with ConstantUnit`` () =
AnonymousModule() { Value("x", ConstantExpr(ConstantUnit())) }
|> produces
"""

let x = ()
"""

[<Test>]
let ``let value with a ConstantExpr expression with MeasureOperator`` () =
AnonymousModule() {
Value(
"x",
ConstantExpr(
ConstantMeasure(
ConstantString("55.0f"),
MeasureOperator("*", MeasureSingle("miles"), MeasureSingle("hour"))
)
)
)
}
|> produces
"""

let x = 55.0f<miles * hour>
"""

[<Test>]
let ``let value with a ConstantExpr expression with MeasureDivide`` () =
AnonymousModule() {
Value(
"x",
ConstantExpr(
ConstantMeasure(
ConstantString("55.0f"),
MeasureDivide("/", MeasureSingle("miles"), MeasureSingle("hour"))
)
)
)
}
|> produces
"""

let x = 55.0f<miles / hour>
"""

[<Test>]
let ``let value with a ConstantExpr expression with MeasureDivide 2`` () =
AnonymousModule() {
Value(
"x",
InfixAppExpr(
ConstantExpr(ConstantString "55.0f"),
"/",
ConstantExpr(
ConstantMeasure(
ConstantString "1000.0",
MeasureDivide("/", MeasureSingle("g"), MeasureSingle("kg"))
)
)
)
)
}
|> produces
"""

let x = 55.0f / 1000.0<g / kg>
"""


[<Test>]
let ``let value with a ConstantExpr expression with MeasurePower`` () =
AnonymousModule() {
Value(
"x",
ConstantExpr(
ConstantMeasure(
ConstantString("55.0f"),
MeasurePower("*", MeasureSingle("miles"), RationalConstInteger("hour"))
)
)
)
}
|> produces
"""

let x = 55.0f<miles*hour>
"""
2 changes: 1 addition & 1 deletion src/Fabulous.AST.Tests/Expressions/InfixApp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module InfixApp =

[<Test>]
let ``let value with a InfixApp expression`` () =
AnonymousModule() { InfixAppExpr(ConstantExpr("a"), "|>", ConstantExpr("b")) }
AnonymousModule() { InfixAppExpr(ConstantExpr(ConstantString "a"), "|>", ConstantExpr(ConstantString "b")) }
|> produces
"""

Expand Down
4 changes: 2 additions & 2 deletions src/Fabulous.AST.Tests/Expressions/Lazy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let x = lazy 12

[<Test>]
let ``let value with a lazy expression widgets`` () =
AnonymousModule() { Value("x", LazyExpr(ConstantExpr("12"))) }
AnonymousModule() { Value("x", LazyExpr(ConstantExpr(ConstantString "12"))) }
|> produces
"""

Expand All @@ -29,7 +29,7 @@ let x = lazy 12

[<Test>]
let ``let value with a lazy expression in parenthesis`` () =
AnonymousModule() { Value("x", LazyExpr(ParenExpr(ConstantExpr("12")))) }
AnonymousModule() { Value("x", LazyExpr(ParenExpr(ConstantExpr(ConstantString "12")))) }
|> produces
"""

Expand Down
6 changes: 3 additions & 3 deletions src/Fabulous.AST.Tests/Expressions/Match.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ module Match =
AnonymousModule() {
MatchExpr(
ListExpr() {
ConstantExpr("1")
ConstantExpr("2")
ConstantExpr(ConstantString "1")
ConstantExpr(ConstantString "2")
}
) {
MatchClauseExpr(NamedPat("a"), ConstantExpr("3"))
MatchClauseExpr(NamedPat("a"), ConstantExpr(ConstantString "3"))
}
}
|> produces
Expand Down
6 changes: 4 additions & 2 deletions src/Fabulous.AST.Tests/Expressions/New.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module New =

[<Test>]
let ``let value with a New expression`` () =
AnonymousModule() { Value("x", NewExpr(CommonType.mkLongIdent("MyType"), ConstantExpr("12"))) }
AnonymousModule() { Value("x", NewExpr(CommonType.mkLongIdent("MyType"), ConstantExpr(ConstantString "12"))) }
|> produces
"""

Expand All @@ -20,7 +20,9 @@ let x = new MyType 12

[<Test>]
let ``let value with a New expression with parenthesis`` () =
AnonymousModule() { Value("x", NewExpr(CommonType.mkLongIdent("MyType"), ParenExpr(ConstantExpr("12")))) }
AnonymousModule() {
Value("x", NewExpr(CommonType.mkLongIdent("MyType"), ParenExpr(ConstantExpr(ConstantString "12"))))
}
|> produces
"""

Expand Down
2 changes: 1 addition & 1 deletion src/Fabulous.AST.Tests/Expressions/Paren.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ open type Ast
module Paren =
[<Test>]
let ``let value with a expression wrapped parenthesis`` () =
AnonymousModule() { Value("x", ParenExpr(ConstantExpr("12"))) }
AnonymousModule() { Value("x", ParenExpr(ConstantExpr(ConstantString "12"))) }
|> produces
"""

Expand Down
2 changes: 1 addition & 1 deletion src/Fabulous.AST.Tests/Expressions/Quoted.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ open type Ast
module Quoted =
[<Test>]
let ``let value with a Quoted expression`` () =
AnonymousModule() { Value("x", QuotedExpr(ConstantExpr("12"))) }
AnonymousModule() { Value("x", QuotedExpr(ConstantExpr(ConstantString "12"))) }
|> produces
"""

Expand Down
12 changes: 8 additions & 4 deletions src/Fabulous.AST.Tests/Expressions/Record.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,35 @@ module RecordExpr =

[<Test>]
let ``RecordExpr expression`` () =
AnonymousModule() { RecordExpr() { RecordFieldExpr("A", ConstantExpr("1")) } }
AnonymousModule() { RecordExpr() { RecordFieldExpr("A", ConstantExpr(ConstantString "1")) } }
|> produces
"""
{ A = 1 }
"""

[<Test>]
let ``RecordExpr expression with copy info`` () =
AnonymousModule() { RecordExpr(ConstantExpr("A")) { RecordFieldExpr("B", ConstantExpr("1")) } }
AnonymousModule() {
RecordExpr(ConstantExpr(ConstantString "A")) { RecordFieldExpr("B", ConstantExpr(ConstantString "1")) }
}
|> produces
"""
{ A with B = 1 }
"""

[<Test>]
let ``AnonRecordExpr expression`` () =
AnonymousModule() { AnonRecordExpr() { RecordFieldExpr("A", ConstantExpr("1")) } }
AnonymousModule() { AnonRecordExpr() { RecordFieldExpr("A", ConstantExpr(ConstantString "1")) } }
|> produces
"""
{| A = 1 |}
"""

[<Test>]
let ``AnonRecordExpr expression with copy info`` () =
AnonymousModule() { AnonRecordExpr(ConstantExpr("A")) { RecordFieldExpr("B", ConstantExpr("1")) } }
AnonymousModule() {
AnonRecordExpr(ConstantExpr(ConstantString "A")) { RecordFieldExpr("B", ConstantExpr(ConstantString "1")) }
}
|> produces
"""
{| A with B = 1 |}
Expand Down
2 changes: 1 addition & 1 deletion src/Fabulous.AST.Tests/Expressions/Single.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ open type Ast
module Single =
[<Test>]
let ``let value with a Single expression`` () =
AnonymousModule() { Value("x", SingleExpr("a", true, false, ConstantExpr("b"))) }
AnonymousModule() { Value("x", SingleExpr("a", true, false, ConstantExpr(ConstantString "b"))) }
|> produces
"""

Expand Down
12 changes: 6 additions & 6 deletions src/Fabulous.AST.Tests/Expressions/StructTuple.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ module StructTuple =
Value(
"x",
StructTupleExpr() {
ConstantExpr("1")
ConstantExpr("2")
ConstantExpr("3")
ConstantExpr(ConstantString "1")
ConstantExpr(ConstantString "2")
ConstantExpr(ConstantString "3")
}
)
}
Expand All @@ -34,9 +34,9 @@ let x = struct (1, 2, 3)
"x",
ParenExpr(
StructTupleExpr() {
ConstantExpr("1")
ConstantExpr("2")
ConstantExpr("3")
ConstantExpr(ConstantString "1")
ConstantExpr(ConstantString "2")
ConstantExpr(ConstantString "3")
}
)
)
Expand Down
12 changes: 6 additions & 6 deletions src/Fabulous.AST.Tests/Expressions/Tuple.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ module Tuple =
Value(
"x",
TupleExpr() {
ConstantExpr("1")
ConstantExpr("2")
ConstantExpr("3")
ConstantExpr(ConstantString "1")
ConstantExpr(ConstantString "2")
ConstantExpr(ConstantString "3")
}
)
}
Expand All @@ -34,9 +34,9 @@ let x = 1, 2, 3
"x",
ParenExpr(
TupleExpr() {
ConstantExpr("1")
ConstantExpr("2")
ConstantExpr("3")
ConstantExpr(ConstantString "1")
ConstantExpr(ConstantString "2")
ConstantExpr(ConstantString "3")
}
)
)
Expand Down
2 changes: 1 addition & 1 deletion src/Fabulous.AST.Tests/Expressions/Typed.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ open type Ast
module Typed =
[<Test>]
let ``let value with a typed expression`` () =
AnonymousModule() { Value("x", TypedExpr(ConstantExpr("2"), ":", CommonType.String)) }
AnonymousModule() { Value("x", TypedExpr(ConstantExpr(ConstantString "2"), ":", CommonType.String)) }
|> produces
"""

Expand Down
1 change: 1 addition & 0 deletions src/Fabulous.AST.Tests/Fabulous.AST.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<Compile Include="Expressions\StructTuple.fs" />
<Compile Include="Expressions\ArrayOrList.fs" />
<Compile Include="Expressions\App.fs" />
<Compile Include="Expressions\Constant.fs" />
<Compile Include="Expressions\Match.fs" />
<Compile Include="Expressions\InfixApp.fs" />
<Compile Include="Expressions\Record.fs" />
Expand Down