225 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			225 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package analyzer
 | |
| 
 | |
| import "testing"
 | |
| 
 | |
| func TestTypedefUniqueErr (test *testing.T) {
 | |
| testStringErr (test,
 | |
| "Hello already declared at stream0.fspl:2:1", 3, 1,
 | |
| `
 | |
| Hello: *Int
 | |
| Hello: (. x:Int y:Int)
 | |
| `)
 | |
| }
 | |
| 
 | |
| func TestTypedefUniqueErrShadowPrimitive (test *testing.T) {
 | |
| testStringErr (test,
 | |
| "cannot shadow primitive U8", 2, 1,
 | |
| `
 | |
| U8: Int
 | |
| `)
 | |
| }
 | |
| 
 | |
| func TestTypedefUniqueErrShadowBuiltin (test *testing.T) {
 | |
| testStringErr (test,
 | |
| "cannot shadow builtin String", 2, 1,
 | |
| `
 | |
| String: Int
 | |
| `)
 | |
| }
 | |
| 
 | |
| func TestTypedefUnique (test *testing.T) {
 | |
| testString (test,
 | |
| `
 | |
| Hello: *Int
 | |
| World: (. x:Int y:Int)
 | |
| `)
 | |
| }
 | |
| 
 | |
| func TestTypedefRecursiveErr (test *testing.T) {
 | |
| testStringErr (test,
 | |
| "type List cannot be used in this context", 4, 9,
 | |
| `
 | |
| List: (.
 | |
| 	value: Int
 | |
| 	next:  List)
 | |
| `)
 | |
| }
 | |
| 
 | |
| func TestTypedefRecursive (test *testing.T) {
 | |
| testString (test,
 | |
| `
 | |
| List: (.
 | |
| 	value: Int
 | |
| 	next: *List)
 | |
| `)
 | |
| }
 | |
| 
 | |
| func TestTypeNamedErrMissing (test *testing.T) {
 | |
| testStringErr (test,
 | |
| "no type named Missing", 2, 10,
 | |
| `
 | |
| Present: Missing
 | |
| `)
 | |
| }
 | |
| 
 | |
| func TestTypeNamed (test *testing.T) {
 | |
| testString (test,
 | |
| `
 | |
| Example: Int
 | |
| AllBuiltin: (.
 | |
| 	int:    Int
 | |
| 	uint:   UInt
 | |
| 	byte:   Byte
 | |
| 	rune:   Rune
 | |
| 	string: String
 | |
| 	i8:     I8
 | |
| 	i16:    I16
 | |
| 	i32:    I32
 | |
| 	i64:    I64
 | |
| 	u8:     U8
 | |
| 	u16:    U16
 | |
| 	u32:    U32
 | |
| 	u64:    U64
 | |
| 	f32:    F32
 | |
| 	f64:    F64
 | |
| 	bool:   Bool)
 | |
| [main] = {
 | |
| 	example:Example
 | |
| 	allBuiltin:AllBuiltin
 | |
| }
 | |
| `)
 | |
| }
 | |
| 
 | |
| func TestTypePointer (test *testing.T) {
 | |
| testString (test,
 | |
| `
 | |
| Ptr: *Int
 | |
| PtrPtr: **Int
 | |
| PtrPtrPtr: *PtrPtr
 | |
| ArrPtr: *5:Int
 | |
| SlicePtr: **:Int
 | |
| `)
 | |
| }
 | |
| 
 | |
| func TestTypeSlice (test *testing.T) {
 | |
| testString (test,
 | |
| `
 | |
| Slice: *:Int
 | |
| RaggedSlice: *:*:Int
 | |
| `)
 | |
| }
 | |
| 
 | |
| func TestTypeArrayErrSizeZero (test *testing.T) {
 | |
| testStringErr (test,
 | |
| "array length must be > 0", 2, 8,
 | |
| `
 | |
| Array: 0:Int
 | |
| `)
 | |
| }
 | |
| 
 | |
| func TestTypeArray (test *testing.T) {
 | |
| testString (test,
 | |
| `
 | |
| Array: 5:Int
 | |
| Matrix: 5:6:Int
 | |
| `)
 | |
| }
 | |
| 
 | |
| func TestTypeStructMemberUniqueErr (test *testing.T) {
 | |
| testStringErr (test,
 | |
| "x already listed in struct at stream0.fspl:3:2", 6, 2,
 | |
| `
 | |
| Bird: (.
 | |
| 	x:Int
 | |
| 	y:Int
 | |
| 	z:Int
 | |
| 	x:U8)
 | |
| `)
 | |
| }
 | |
| 
 | |
| func TestTypeStructMemberUnique (test *testing.T) {
 | |
| testString (test,
 | |
| `
 | |
| Bird: (.
 | |
| 	x:Int
 | |
| 	y:Int
 | |
| 	z:Int
 | |
| 	a:U8)
 | |
| `)
 | |
| }
 | |
| 
 | |
| func TestTypeUnion (test *testing.T) {
 | |
| testString (test,
 | |
| `
 | |
| U: (| I8 I16 I32 I64 Int)
 | |
| Point: (. x:Int y:Int)
 | |
| Error: (& [error]:String)
 | |
| PointOrError: (| Point Error)
 | |
| `)
 | |
| }
 | |
| 
 | |
| func TestTypeUnionAllowedUnique (test *testing.T) {
 | |
| testString (test,
 | |
| `
 | |
| SomeInt: Int
 | |
| U: (|
 | |
| 	U8
 | |
| 	U16
 | |
| 	(. x:Int)
 | |
| 	Int
 | |
| 	(. x:SomeInt))
 | |
| `)
 | |
| }
 | |
| 
 | |
| func TestTypeUnionAllowedUniqueErrPrimitive (test *testing.T) {
 | |
| testStringErr (test,
 | |
| "Int already listed in union at stream0.fspl:2:10", 2, 26,
 | |
| `
 | |
| U: (| I8 Int I16 I32 I64 Int I64)
 | |
| `)
 | |
| }
 | |
| 
 | |
| func TestTypeUnionAllowedUniqueErrComposite (test *testing.T) {
 | |
| testStringErr (test,
 | |
| "(. x:Int) already listed in union at stream0.fspl:5:3", 7, 3,
 | |
| `
 | |
| U: (|
 | |
| 	U8
 | |
| 	U16
 | |
| 	(. x:Int)
 | |
| 	Int
 | |
| 	(. x:Int))
 | |
| `)
 | |
| }
 | |
| 
 | |
| func TestTypeInterfaceBehaviorUniqueErr (test *testing.T) {
 | |
| testStringErr (test,
 | |
| "fly already listed in interface at stream0.fspl:2:10", 2, 16,
 | |
| `
 | |
| Bird: (& [fly] [fly])
 | |
| `)
 | |
| }
 | |
| 
 | |
| func TestTypeInterfaceBehaviorUnique (test *testing.T) {
 | |
| testString (test,
 | |
| `
 | |
| Bird: (& [fly] [land])
 | |
| `)
 | |
| }
 | |
| 
 | |
| func TestTypeIntegerLiteralVoid (test *testing.T) {
 | |
| testStringErr (test,
 | |
| "cannot use integer literal as Void", 2, 10,
 | |
| `
 | |
| [main] = 5
 | |
| `)
 | |
| }
 | |
| 
 | |
| func TestTypeStringLiteralVoid (test *testing.T) {
 | |
| testStringErr (test,
 | |
| "cannot use string literal as Void", 2, 10,
 | |
| `
 | |
| [main] = 'hello'
 | |
| `)
 | |
| }
 |