-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/std-text
- Loading branch information
Showing
18 changed files
with
179 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use crate::compiler::AmberCompiler; | ||
use crate::Cli; | ||
use crate::test_amber; | ||
|
||
#[test] | ||
#[should_panic(expected = "ERROR: Return type does not match function return type")] | ||
fn function_with_wrong_typed_return() { | ||
let code = r#" | ||
pub fun test(): Num { | ||
return "Hello, World!" | ||
} | ||
echo test() | ||
"#; | ||
|
||
test_amber!(code, "Hello, World!"); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "ERROR: Failable functions must return a Failable type")] | ||
fn function_failable_with_typed_nonfailable_return() { | ||
let code = r#" | ||
pub fun test(): Null { | ||
fail 1 | ||
} | ||
echo test() failed: echo "Failed" | ||
"#; | ||
|
||
test_amber!(code, "Failed"); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "ERROR: Non-failable functions cannot return a Failable type")] | ||
fn function_nonfailable_with_typed_failable_return() { | ||
let code = r#" | ||
pub fun test(): Null? { | ||
echo "Hello, World!" | ||
} | ||
echo test() failed: echo "Failed" | ||
"#; | ||
|
||
test_amber!(code, "Hello, World!"); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "ERROR: Failable types cannot be used as arguments")] | ||
fn function_with_failable_typed_arg() { | ||
let code = r#" | ||
pub fun test(a: Text?) { | ||
echo a | ||
} | ||
test("Hello, World!") | ||
"#; | ||
|
||
test_amber!(code, "Hello, World!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ use crate::Cli; | |
|
||
pub mod cli; | ||
pub mod formatter; | ||
pub mod errors; | ||
pub mod stdlib; | ||
pub mod validity; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
fun failable(): Num? { | ||
if 0 > 5 { | ||
fail 1 | ||
} | ||
|
||
return 1 | ||
} | ||
|
||
let a = failable() failed: echo "Failed" | ||
|
||
if a is Num: echo "Succeded" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
fun failable(): Num? { | ||
if 0 > 5 { | ||
fail 1 | ||
} | ||
|
||
return 1 | ||
} | ||
|
||
let a = failable() failed: echo "Failed" | ||
|
||
if a is Num: echo "Succeded" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
fun test() { | ||
if 0 < 5 { | ||
fail 1 | ||
} | ||
|
||
return 42 | ||
} | ||
|
||
test() failed: echo "Succeded" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pub fun test(): Num? { | ||
if 0 < 5 { | ||
fail 1 | ||
} | ||
|
||
return 42 | ||
} | ||
|
||
echo test() failed: echo "Succeded" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub fun test(): Text { | ||
return "Succeded" | ||
} | ||
|
||
echo test() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
fun test(): Num? { | ||
if 0 < 5 { | ||
fail 1 | ||
} | ||
|
||
return 42 | ||
} | ||
|
||
if unsafe test() is Num: echo "Succeded" |