-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stdlib): extract function (#587)
- Loading branch information
Showing
7 changed files
with
178 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { contains_all } from "std/text" | ||
|
||
// Output | ||
// None: 0 | ||
// One: 0 | ||
// Right: 1 | ||
// Both: 1 | ||
|
||
fun test_multiple(label, text, terms) { | ||
let result = contains_all(text, terms) | ||
echo "{label}: {result}" | ||
} | ||
|
||
main { | ||
test_multiple("None", "Hello World", ["Other", "Other"]) | ||
test_multiple("One", "Hello World", ["World", "Something"]) | ||
test_multiple("Right", "Hello World", ["World", "Hello"]) | ||
test_multiple("Both", "Hello World", ["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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { contains_any } from "std/text" | ||
|
||
// Output | ||
// Empty: 0 | ||
// None: 0 | ||
// Left: 1 | ||
// Right: 1 | ||
// Both: 1 | ||
|
||
fun test_multiple(label, text, terms) { | ||
let result = contains_any(text, terms) | ||
echo "{label}: {result}" | ||
} | ||
|
||
main { | ||
test_multiple("Empty", "Hello World", [Text]) | ||
test_multiple("None", "Hello World", ["Other", "Other"]) | ||
test_multiple("Left", "Hello World", ["Hello", "Other"]) | ||
test_multiple("Right", "Hello World", ["Other", "World"]) | ||
test_multiple("Both", "Hello World", ["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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * from "std/fs" | ||
import { includes } from "std/array" | ||
|
||
main { | ||
let tmpdir = trust $ mktemp -d /tmp/amber-XXXX $ | ||
cd tmpdir | ||
trust $ touch test.txt $ | ||
silent trust $tar -czf "filename.tar.gz" "{tmpdir}/test.txt"$ | ||
trust $ rm "test.txt" $ | ||
let package = tmpdir + "/" + "filename.tar.gz" | ||
|
||
extract(package, tmpdir) failed { | ||
echo "Error" | ||
} | ||
|
||
if dir_exist(tmpdir + "/" + tmpdir) { | ||
echo "Succeeded" | ||
} | ||
|
||
trust $ rm -rf "{tmpdir}" $ | ||
} |
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,21 @@ | ||
import { match_any_regex } from "std/text" | ||
|
||
// Output | ||
// Empty: 0 | ||
// None: 0 | ||
// Right: 1 | ||
// Left: 1 | ||
// Both: 1 | ||
|
||
fun test_multiple(label, text, terms) { | ||
let result = match_any_regex(text, terms) | ||
echo "{label}: {result}" | ||
} | ||
|
||
main { | ||
test_multiple("Empty", "Hello World", [Text]) | ||
test_multiple("None", "Hello World", ["Other", "Other$"]) | ||
test_multiple("Right", "Hello World", ["Other", "World$"]) | ||
test_multiple("Left", "Hello World", ["^Hello", "Other"]) | ||
test_multiple("Both", "Hello World", ["^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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { match_regex } from "std/text" | ||
|
||
main { | ||
if match_regex("Hello World", "World$") { | ||
echo "Succeeded" | ||
} | ||
} |