-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Syntaxic sugar over anonymous objects closes #298
- Loading branch information
Showing
7 changed files
with
210 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import "std"; | ||
|
||
fun pack([str] names) > obj{ str, str, str } { | ||
return .{ | ||
names[0], | ||
names[1], | ||
names[2], | ||
}; | ||
} | ||
|
||
test "Tuples" { | ||
const tuple = .{ "joe", "doe" }; | ||
|
||
std.assert(tuple.@"0" == "joe" and tuple.@"1" == "doe"); | ||
|
||
const name = "Joe"; | ||
const age = 42; | ||
|
||
| Forced tuple | ||
const another = .{ (name), (age) }; | ||
|
||
std.assert(another.@"0" == "Joe" and another.@"1" == 42); | ||
|
||
const names = pack(["Joe", "John", "James"]); | ||
|
||
std.assert(names.@"0" == "Joe" and names.@"1" == "John"); | ||
} |
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,4 @@ | ||
| Tuples can't have more than 4 elements | ||
test "Long tuple" { | ||
.{ 1, 2, 3, 4, 5 }; | ||
} |
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,4 @@ | ||
| Can't mix tuple notation and regular properties in anonymous object initialization | ||
test "Mixing tuple notation and regular anonymous object" { | ||
.{ name = "Joe", 42 }; | ||
} |