mirror of
https://github.com/tests-always-included/mo.git
synced 2025-11-19 23:34:32 +01:00
All tests pass.
Specs: 181 total, 111 pass (with 7 overridden), 63 fail, 7 skip.
This commit is contained in:
@@ -16,6 +16,10 @@ template() {
|
||||
... this is the last line.
|
||||
EOF
|
||||
}
|
||||
export expected=$'<b> Willy is awesome.</b>\n... this is the last line.\n'
|
||||
|
||||
# We don't expect {{name}} to be changed. The function returns whatever content
|
||||
# that should be the result. There is a separate test where the function handles
|
||||
# parsing mustache tags.
|
||||
export expected=$'<b> {{name}} is awesome.</b>\n... this is the last line.\n'
|
||||
|
||||
runTest
|
||||
|
||||
16
tests/function-alternate-delimiters
Executable file
16
tests/function-alternate-delimiters
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
cd "${0%/*}" || exit 1
|
||||
. ../run-tests
|
||||
|
||||
export planet=Earth
|
||||
lambda() {
|
||||
local content
|
||||
|
||||
content=$(cat)
|
||||
mo::parse content "$content{{planet}} => |planet|$content"
|
||||
echo -n "$content"
|
||||
}
|
||||
export template="{{= | | =}}<|#lambda|-|/lambda|>"
|
||||
export expected="<-{{planet}} => Earth->"
|
||||
|
||||
runTest
|
||||
@@ -20,7 +20,7 @@ template() {
|
||||
No args: {{testArgs}} - done
|
||||
One arg: {{testArgs 'one'}} - done
|
||||
Getting name in a string: {{testArgs {"The name is " name}}} - done
|
||||
Reverse this: {{#pipeTo "rev"}}abcde{{/pipeTo}}
|
||||
Reverse this: {{#pipeTo "rev"}}abcde{{/pipeTo "rev"}}
|
||||
EOF
|
||||
}
|
||||
expected() {
|
||||
|
||||
28
tests/function-with-more-parsing
Executable file
28
tests/function-with-more-parsing
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
cd "${0%/*}" || exit 1
|
||||
. ../run-tests
|
||||
|
||||
export name=Willy
|
||||
wrapped() {
|
||||
local content
|
||||
|
||||
# Wrapping 'cat' in a subshell eats the trailing whitespace
|
||||
content="<b>$(cat)</b>"
|
||||
|
||||
# Parse the content using mustache
|
||||
mo::parse content "$content"
|
||||
|
||||
# The echo adds a newline, which is preserved.
|
||||
echo "$content"
|
||||
}
|
||||
template() {
|
||||
cat <<EOF
|
||||
{{#wrapped}}
|
||||
{{name}} is awesome.
|
||||
{{/wrapped}}
|
||||
... this is the last line.
|
||||
EOF
|
||||
}
|
||||
export expected=$'<b> Willy is awesome.</b>\n... this is the last line.\n'
|
||||
|
||||
runTest
|
||||
@@ -54,6 +54,7 @@ MO_ALLOW_FUNCTION_ARGUMENTS - When set to a non-empty value, this allows
|
||||
functions referenced in templates to receive additional options and
|
||||
arguments.
|
||||
MO_CLOSE_DELIMITER - The string used when closing a tag. Defaults to "}}".
|
||||
MO_CURRENT - Variable name to use for ".".
|
||||
MO_DEBUG - When set to a non-empty value, additional debug information is
|
||||
written to stderr.
|
||||
MO_FUNCTION_ARGS - Arguments passed to the function.
|
||||
|
||||
53
tests/variable-braces-and-parenthesis
Executable file
53
tests/variable-braces-and-parenthesis
Executable file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env bash
|
||||
cd "${0%/*}" || exit 1
|
||||
. ../run-tests
|
||||
|
||||
export array=("wrong0" "item1" "wrong2")
|
||||
export index=1
|
||||
|
||||
# Example #8 is weird because of how the variable name is parsed. Considering
|
||||
# it's an edge case when a user probably has a bug in a template, I think we're
|
||||
# good leaving it as-is until a bug report is filed.
|
||||
|
||||
template() {
|
||||
cat <<'EOF'
|
||||
Starting point:
|
||||
1 "{{ array.1 }}" = "item1"
|
||||
|
||||
Whole expression:
|
||||
2 "{{ {'array.' index} }}" = "array.1"
|
||||
3 "{{ ('array.' index) }}" = "item1"
|
||||
|
||||
Partial expression:
|
||||
4 "{{ 'array.' {index} }}" = "array.1"
|
||||
5 "{{ 'array.' (index) }}" = "array."
|
||||
|
||||
Combined:
|
||||
6 "{{ {'array.' {index}} }}" = "array.1"
|
||||
7 "{{ {'array.' (index)} }}" = "array."
|
||||
8 "{{ ('array.' (index)) }}" = "wrong0,item1,wrong2"
|
||||
9 "{{ ('array.' {index}) }}" = "item1"
|
||||
EOF
|
||||
}
|
||||
|
||||
expected() {
|
||||
cat <<'EOF'
|
||||
Starting point:
|
||||
1 "item1" = "item1"
|
||||
|
||||
Whole expression:
|
||||
2 "array.1" = "array.1"
|
||||
3 "item1" = "item1"
|
||||
|
||||
Partial expression:
|
||||
4 "array.1" = "array.1"
|
||||
5 "array." = "array."
|
||||
|
||||
Combined:
|
||||
6 "array.1" = "array.1"
|
||||
7 "array." = "array."
|
||||
8 "wrong0,item1,wrong2" = "wrong0,item1,wrong2"
|
||||
9 "item1" = "item1"
|
||||
EOF
|
||||
}
|
||||
runTest
|
||||
Reference in New Issue
Block a user