268 lines
5.5 KiB
Go
268 lines
5.5 KiB
Go
package fsplParser
|
|
|
|
import "testing"
|
|
|
|
func TestType (test *testing.T) {
|
|
testString (test,
|
|
// correct
|
|
`- BasicInt: Int
|
|
- Structure: (. x:Int y:Int)
|
|
- Interface: (& [aMethod x:Int]:*U8 [otherMethod arg:5:Int]:*U8)
|
|
- Union: (| Int F64 *:U8 (. x:Int y:Int))
|
|
- Array: 16:16:16:Int
|
|
- StructArray: 31:24:340920:(. x:Int y:Int)
|
|
- String: *:U8
|
|
+ FileDescriptor: I32
|
|
| stdin 0
|
|
| stdout 1
|
|
| stderr 2`,
|
|
// input
|
|
`
|
|
BasicInt: Int
|
|
Structure: (.
|
|
x:Int
|
|
y:Int)
|
|
Interface: (&
|
|
[aMethod x:Int]:*U8
|
|
[otherMethod arg:5:Int]:*U8)
|
|
- Union: (|
|
|
Int F64 *:U8
|
|
(. x:Int y:Int))
|
|
Array: 16:16:16:Int
|
|
StructArray: 31:24:340920:(.
|
|
x:Int
|
|
y:Int)
|
|
String: *:U8
|
|
+ FileDescriptor: I32
|
|
| stdin 0
|
|
| stdout 1
|
|
| stderr 2
|
|
`)
|
|
}
|
|
|
|
func TestLiteral (test *testing.T) {
|
|
testString (test,
|
|
// correct
|
|
`- [int]:Int = 5
|
|
- [float]:F64 = 324.23409
|
|
- [boolean]:Bool = true
|
|
- [boolean2]:Bool = false
|
|
- [struct]:(. x:Int y:(. w:F64 z:F64)) = (. x:1 y:(. w:1.2 z:78.5))
|
|
- [string]:String = 'hahah \'sup\005'`,
|
|
// input
|
|
`
|
|
[int]:Int = 5
|
|
[float]:F64 = 324.23409
|
|
[boolean]:Bool = true
|
|
[boolean2]:Bool = false
|
|
[struct]:(. x:Int y:(. w:F64 z:F64)) = (. x: 1 y: (. w: 1.2 z: 78.5))
|
|
[string]:String = 'hahah \'sup\005'
|
|
`)
|
|
}
|
|
|
|
func TestExpression (test *testing.T) {
|
|
testString (test,
|
|
// correct
|
|
`- [var] = sdfdf
|
|
- [memberAccess] = [~ T sdfdf].a.x.y.z
|
|
- [methodAccess] = sdfdf.[method 238 9 203]
|
|
- [declaration] = sdfdf:Int
|
|
- [call] = [print 3 1]
|
|
- [emptyBlock] = {}
|
|
- [nestedBlock] = {342 93.34 {3948 32}}
|
|
- [subscript] = [.(3 1 2 4) 3]
|
|
- [slice] = [\(1 2 3 4 5 6 7 8 9) consumed/]
|
|
- [dereference] = [.ptr]
|
|
- [reference] = [@val]
|
|
- [valueCast] = [~ F32 someValue]
|
|
- [bitCast] = [~~ 4:U8 someValue]
|
|
- [math] = {[+ 3 4 2 [/ 24 3]] [|| 3 [<< 56 4]] [++ 3] [-- 3] [- 3 1]}
|
|
- [ifElse]:Int = if true then 4 else 5
|
|
- [dangleElse]:Int = if true then if false then 3 else 5
|
|
- [loop]:Int = {i:Int=0 if [< i 3] then return 1 loop {[print 3] if [> i 3] then break 0 i=[++ i]}}
|
|
- [for s:String] = for i:Index e:Byte in str if [> i 3] then [break e]
|
|
- [for s:String] = for e:Byte in s [break e]
|
|
- [matchToInt u:(| Int F64)]:Int = match u | u:Int u | u:F64 [~ Int u] * 0
|
|
- [switch x:Int] = switch x | 0 5 | 1 4 | 2 3 * 0
|
|
- [whatFile fd:FD]:String = switch fd | FD.stdin 'in' | FD.stdout 'out' * '?'`,
|
|
// input
|
|
`
|
|
[var] = sdfdf
|
|
[memberAccess] = [~ T sdfdf].a.x.y.z
|
|
[methodAccess] = sdfdf.[method 238 9 203]
|
|
[declaration] = sdfdf:Int
|
|
[call] = [print 3 1]
|
|
[emptyBlock] = { }
|
|
[nestedBlock] = {
|
|
342
|
|
93.34
|
|
{
|
|
3948
|
|
32
|
|
}
|
|
}
|
|
[subscript] = [. (3 1 2 4) 3]
|
|
[slice] = [\ (1 2 3 4 5 6 7 8 9) consumed/]
|
|
[dereference] = [. ptr]
|
|
[reference] = [@ val]
|
|
[valueCast] = [~ F32 someValue]
|
|
[bitCast] = [~~ 4:U8 someValue]
|
|
[math] = {
|
|
[+ 3 4 2 [/ 24 3]]
|
|
[|| 3 [<< 56 4]]
|
|
[++ 3]
|
|
[-- 3]
|
|
[- 3 1]
|
|
}
|
|
[ifElse]:Int = if true then 4 else 5
|
|
[dangleElse]:Int =
|
|
if true then
|
|
if false then
|
|
3
|
|
else
|
|
5
|
|
[loop]:Int = {
|
|
i:Int = 0
|
|
if [< i 3] then return 1
|
|
loop {
|
|
[print 3]
|
|
if [> i 3] then break 0
|
|
i = [++ i]
|
|
}
|
|
}
|
|
[for s:String] = for i:Index e:Byte in str
|
|
if [> i 3] then [break e]
|
|
[for s:String] = for e:Byte in s
|
|
[break e]
|
|
[matchToInt u:(| Int F64)]:Int = match u
|
|
| u:Int u
|
|
| u:F64 [~Int u]
|
|
* 0
|
|
[switch x:Int] = switch x
|
|
| 0 5
|
|
| 1 4
|
|
| 2 3
|
|
* 0
|
|
[whatFile fd:FD]:String = switch fd
|
|
| FD.stdin 'in'
|
|
| FD.stdout 'out'
|
|
* '?'
|
|
`)
|
|
}
|
|
|
|
func TestFunction (test *testing.T) {
|
|
testString (test,
|
|
// correct
|
|
`- [arguments x:Int y:Int z:Int] = {}
|
|
- [arrayArguments arg:4:54:23:28:(. x:Int y:Int)] = {}`,
|
|
//input
|
|
`
|
|
[arguments x:Int y:Int z:Int] = { }
|
|
[arrayArguments arg:4:54:23:28:(. x:Int y:Int)] = { }
|
|
`)
|
|
}
|
|
|
|
func TestMethod (test *testing.T) {
|
|
testString (test,
|
|
// correct
|
|
`- BopIt: Int
|
|
- BopIt.[bop force:UInt] = {}
|
|
- BopIt.[twist angle:F64] = {}
|
|
- BopIt.[pull distance:Int] = {}`,
|
|
//input
|
|
`
|
|
BopIt: Int
|
|
BopIt.[bop force:UInt] = { }
|
|
BopIt.[twist angle:F64] = { }
|
|
BopIt.[pull distance:Int] = { }
|
|
`)
|
|
}
|
|
|
|
func TestAccess (test *testing.T) {
|
|
testString (test,
|
|
// correct
|
|
`+ PublicType: Int
|
|
# OpaqueType: (. x:Int y:Int)
|
|
- PrivateType: String
|
|
- AlsoPrivateType: Byte
|
|
+ [publicFn]:Int = 0
|
|
# [opaqueFn]:(. x:Int y:Int) = (. x:0 y:0)
|
|
- [privateFn]:Rune = 'a'
|
|
- [alsoPrivateFn]:Byte = 0
|
|
- T: Int
|
|
+ T.[publicFn]:Int = 0
|
|
# T.[opaqueFn]:(. x:Int y:Int) = (. x:0 y:0)
|
|
- T.[privateFn]:Rune = 'a'
|
|
- T.[alsoPrivateFn]:Byte = 0`,
|
|
//input
|
|
`
|
|
+ PublicType: Int
|
|
# OpaqueType: (. x:Int y:Int)
|
|
- PrivateType: String
|
|
AlsoPrivateType: Byte
|
|
+ [publicFn]: Int = 0
|
|
# [opaqueFn]: (. x:Int y:Int) = (. x:0 y:0)
|
|
- [privateFn]: Rune = 'a'
|
|
[alsoPrivateFn]: Byte = 0
|
|
T: Int
|
|
+ T.[publicFn]: Int = 0
|
|
# T.[opaqueFn]: (. x:Int y:Int) = (. x:0 y:0)
|
|
- T.[privateFn]: Rune = 'a'
|
|
T.[alsoPrivateFn]: Byte = 0
|
|
`)
|
|
}
|
|
|
|
func TestLinkName (test *testing.T) {
|
|
testString (test,
|
|
// correct
|
|
`- [puts byte:*:Byte]:Index 'puts'
|
|
- File.[write size:Index nmemb:Index]:Index 'fwrite'
|
|
- [main]:Int 'main' = 0`,
|
|
// input
|
|
`
|
|
[puts byte:*:Byte]: Index 'puts'
|
|
File.[write size:Index nmemb:Index]: Index 'fwrite'
|
|
[main]: Int 'main' = 0
|
|
`)
|
|
}
|
|
|
|
func TestModuleNamespace (test *testing.T) {
|
|
testString (test,
|
|
// correct
|
|
`- [hello out:io::Writer] = ioutil::[writeString out 'hello']`,
|
|
// input
|
|
`
|
|
[hello out:io::Writer] = ioutil::[writeString out 'hello']
|
|
`)
|
|
}
|
|
|
|
func TestSkim (test *testing.T) {
|
|
testStringSkim (test,
|
|
// correct
|
|
`- PrivType: Int
|
|
# OpaqueType: Int
|
|
+ ComplexType: (. parser:Parser tree:*Tree skim:Bool)
|
|
+ X: Int
|
|
+ X.[pub]:Int
|
|
- X.[priv]:Int
|
|
+ X.[alreadyExternal]
|
|
+ [alreadyExternal]
|
|
- [priv]
|
|
+ [pub]:X`,
|
|
// input
|
|
`- PrivType:Int
|
|
# OpaqueType:Int
|
|
+ ComplexType: (.
|
|
parser:Parser
|
|
tree:*Tree
|
|
skim:Bool)
|
|
+ X:Int
|
|
+ X.[pub]:Int = 5
|
|
- X.[priv]:Int = 2
|
|
+ X.[alreadyExternal]
|
|
+ [alreadyExternal]
|
|
[priv]
|
|
+ [pub]:X = x:X
|
|
`)
|
|
}
|