Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Lambdas for PowerShell/PSMustache #126

Merged
merged 1 commit into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions specs/~lambdas.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"php": "return \"world\";",
"python": "lambda: \"world\"",
"clojure": "(fn [] \"world\")",
"lisp": "(lambda () \"world\")"
"lisp": "(lambda () \"world\")",
"pwsh": "\"world\""
splumhoff marked this conversation as resolved.
Show resolved Hide resolved
}
},
"template": "Hello, {{lambda}}!",
Expand All @@ -35,7 +36,8 @@
"php": "return \"{{planet}}\";",
"python": "lambda: \"{{planet}}\"",
"clojure": "(fn [] \"{{planet}}\")",
"lisp": "(lambda () \"{{planet}}\")"
"lisp": "(lambda () \"{{planet}}\")",
"pwsh": "\"{{planet}}\""
}
},
"template": "Hello, {{lambda}}!",
Expand All @@ -55,7 +57,8 @@
"php": "return \"|planet| => {{planet}}\";",
"python": "lambda: \"|planet| => {{planet}}\"",
"clojure": "(fn [] \"|planet| => {{planet}}\")",
"lisp": "(lambda () \"|planet| => {{planet}}\")"
"lisp": "(lambda () \"|planet| => {{planet}}\")",
"pwsh": "\"|planet| => {{planet}}\""
}
},
"template": "{{= | | =}}\nHello, (|&lambda|)!",
Expand All @@ -74,7 +77,8 @@
"php": "global $calls; return ++$calls;",
"python": "lambda: globals().update(calls=globals().get(\"calls\",0)+1) or calls",
"clojure": "(def g (atom 0)) (fn [] (swap! g inc))",
"lisp": "(let ((g 0)) (lambda () (incf g)))"
"lisp": "(let ((g 0)) (lambda () (incf g)))",
"pwsh": "if (($null -eq $script:calls) -or ($script:calls -ge 3)){$script:calls=0}; ++$script:calls; $script:calls"
}
},
"template": "{{lambda}} == {{{lambda}}} == {{lambda}}",
Expand All @@ -93,7 +97,8 @@
"php": "return \">\";",
"python": "lambda: \">\"",
"clojure": "(fn [] \">\")",
"lisp": "(lambda () \">\")"
"lisp": "(lambda () \">\")",
"pwsh": "\">\""
}
},
"template": "<{{lambda}}{{{lambda}}}",
Expand All @@ -113,7 +118,8 @@
"php": "return ($text == \"{{x}}\") ? \"yes\" : \"no\";",
"python": "lambda text: text == \"{{x}}\" and \"yes\" or \"no\"",
"clojure": "(fn [text] (if (= text \"{{x}}\") \"yes\" \"no\"))",
"lisp": "(lambda (text) (if (string= text \"{{x}}\") \"yes\" \"no\"))"
"lisp": "(lambda (text) (if (string= text \"{{x}}\") \"yes\" \"no\"))",
"pwsh": "if ($args[0] -eq \"{{x}}\") {\"yes\"} else {\"no\"}"
}
},
"template": "<{{#lambda}}{{x}}{{/lambda}}>",
Expand All @@ -133,7 +139,8 @@
"php": "return $text . \"{{planet}}\" . $text;",
"python": "lambda text: \"%s{{planet}}%s\" % (text, text)",
"clojure": "(fn [text] (str text \"{{planet}}\" text))",
"lisp": "(lambda (text) (format nil \"~a{{planet}}~a\" text text))"
"lisp": "(lambda (text) (format nil \"~a{{planet}}~a\" text text))",
"pwsh": "\"$($args[0]){{planet}}$($args[0])\""
}
},
"template": "<{{#lambda}}-{{/lambda}}>",
Expand All @@ -153,7 +160,8 @@
"php": "return $text . \"{{planet}} => |planet|\" . $text;",
"python": "lambda text: \"%s{{planet}} => |planet|%s\" % (text, text)",
"clojure": "(fn [text] (str text \"{{planet}} => |planet|\" text))",
"lisp": "(lambda (text) (format nil \"~a{{planet}} => |planet|~a\" text text))"
"lisp": "(lambda (text) (format nil \"~a{{planet}} => |planet|~a\" text text))",
"pwsh": "\"$($args[0]){{planet}} => |planet|$($args[0])\""
}
},
"template": "{{= | | =}}<|#lambda|-|/lambda|>",
Expand All @@ -172,7 +180,8 @@
"php": "return \"__\" . $text . \"__\";",
"python": "lambda text: \"__%s__\" % (text)",
"clojure": "(fn [text] (str \"__\" text \"__\"))",
"lisp": "(lambda (text) (format nil \"__~a__\" text))"
"lisp": "(lambda (text) (format nil \"__~a__\" text))",
"pwsh": "\"__$($args[0])__\""
}
},
"template": "{{#lambda}}FILE{{/lambda}} != {{#lambda}}LINE{{/lambda}}",
Expand All @@ -192,7 +201,8 @@
"php": "return false;",
"python": "lambda text: 0",
"clojure": "(fn [text] false)",
"lisp": "(lambda (text) (declare (ignore text)) nil)"
"lisp": "(lambda (text) (declare (ignore text)) nil)",
"pwsh": "$false"
}
},
"template": "<{{^lambda}}{{static}}{{/lambda}}>",
Expand Down
10 changes: 10 additions & 0 deletions specs/~lambdas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ tests:
python: 'lambda: "world"'
clojure: '(fn [] "world")'
lisp: '(lambda () "world")'
pwsh: '"world"'
template: "Hello, {{lambda}}!"
expected: "Hello, world!"

Expand All @@ -40,6 +41,7 @@ tests:
python: 'lambda: "{{planet}}"'
clojure: '(fn [] "{{planet}}")'
lisp: '(lambda () "{{planet}}")'
pwsh: '"{{planet}}"'
template: "Hello, {{lambda}}!"
expected: "Hello, world!"

Expand All @@ -56,6 +58,7 @@ tests:
python: 'lambda: "|planet| => {{planet}}"'
clojure: '(fn [] "|planet| => {{planet}}")'
lisp: '(lambda () "|planet| => {{planet}}")'
pwsh: '"|planet| => {{planet}}"'
template: "{{= | | =}}\nHello, (|&lambda|)!"
expected: "Hello, (|planet| => world)!"

Expand All @@ -71,6 +74,7 @@ tests:
python: 'lambda: globals().update(calls=globals().get("calls",0)+1) or calls'
clojure: '(def g (atom 0)) (fn [] (swap! g inc))'
lisp: '(let ((g 0)) (lambda () (incf g)))'
pwsh: 'if (($null -eq $script:calls) -or ($script:calls -ge 3)){$script:calls=0}; ++$script:calls; $script:calls'
template: '{{lambda}} == {{{lambda}}} == {{lambda}}'
expected: '1 == 2 == 3'

Expand All @@ -86,6 +90,7 @@ tests:
python: 'lambda: ">"'
clojure: '(fn [] ">")'
lisp: '(lambda () ">")'
pwsh: '">"'
template: "<{{lambda}}{{{lambda}}}"
expected: "<&gt;>"

Expand All @@ -102,6 +107,7 @@ tests:
python: 'lambda text: text == "{{x}}" and "yes" or "no"'
clojure: '(fn [text] (if (= text "{{x}}") "yes" "no"))'
lisp: '(lambda (text) (if (string= text "{{x}}") "yes" "no"))'
pwsh: 'if ($args[0] -eq "{{x}}") {"yes"} else {"no"}'
template: "<{{#lambda}}{{x}}{{/lambda}}>"
expected: "<yes>"

Expand All @@ -118,6 +124,7 @@ tests:
python: 'lambda text: "%s{{planet}}%s" % (text, text)'
clojure: '(fn [text] (str text "{{planet}}" text))'
lisp: '(lambda (text) (format nil "~a{{planet}}~a" text text))'
pwsh: '"$($args[0]){{planet}}$($args[0])"'
template: "<{{#lambda}}-{{/lambda}}>"
expected: "<-Earth->"

Expand All @@ -134,6 +141,7 @@ tests:
python: 'lambda text: "%s{{planet}} => |planet|%s" % (text, text)'
clojure: '(fn [text] (str text "{{planet}} => |planet|" text))'
lisp: '(lambda (text) (format nil "~a{{planet}} => |planet|~a" text text))'
pwsh: '"$($args[0]){{planet}} => |planet|$($args[0])"'
template: "{{= | | =}}<|#lambda|-|/lambda|>"
expected: "<-{{planet}} => Earth->"

Expand All @@ -149,6 +157,7 @@ tests:
python: 'lambda text: "__%s__" % (text)'
clojure: '(fn [text] (str "__" text "__"))'
lisp: '(lambda (text) (format nil "__~a__" text))'
pwsh: '"__$($args[0])__"'
template: '{{#lambda}}FILE{{/lambda}} != {{#lambda}}LINE{{/lambda}}'
expected: '__FILE__ != __LINE__'

Expand All @@ -165,5 +174,6 @@ tests:
python: 'lambda text: 0'
clojure: '(fn [text] false)'
lisp: '(lambda (text) (declare (ignore text)) nil)'
pwsh: '$false'
template: "<{{^lambda}}{{static}}{{/lambda}}>"
expected: "<>"