Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: marianoguerra/squim
base: 4fa262d115
...
head fork: marianoguerra/squim
compare: 68188399ce
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 88 additions and 9 deletions.
  1. +1 −1  src/squim.ground.js
  2. +74 −0 test/snippets.test.js
  3. +13 −8 test/squim.test.js
View
2  src/squim.ground.js
@@ -1,4 +1,4 @@
-/*global define SquimError SquimTypes SquimUtil SquimParser*/
+/*global define SquimError SquimTypes SquimUtil SquimParser alert*/
(function (root, factory) {
"use strict";
View
74 test/snippets.test.js
@@ -0,0 +1,74 @@
+/*global define QUnit*/
+(function (root, factory) {
+ "use strict";
+
+ if (typeof define === 'function' && define.amd) {
+ define(['qunit', 'squim'], function (Q, Squim) {
+ return (root.SnippetsTest = factory(Q, Squim));
+ });
+ } else {
+ root.SnippetsTest = factory(root.QUnit, root.Squim);
+ }
+}(this, function (Q, Squim) {
+ "use strict";
+ var obj = {};
+
+ obj.test = function () {
+ var _ground;
+ Q.module("Squim snippets");
+
+ function aliasSquimName(names, env) {
+ var name, newName;
+
+ env.inmutable = false;
+
+ for (name in names) {
+ newName = names[name];
+ env.define(newName, env.get(name));
+ }
+
+ env.inmutable = true;
+ }
+
+ /* Squim related functions */
+ function getGround() {
+ if (_ground === undefined) {
+ _ground = Squim.types.Env.makeGround();
+
+ aliasSquimName({"$define!": "set"}, _ground);
+ }
+
+ return _ground;
+ }
+
+ function runCode(code, bindings) {
+ var env = new Squim.types.Env.fromJsObject(bindings || {}, [getGround()]);
+
+ Squim.run(code, env);
+
+ return env;
+ }
+
+ Q.test("block with sets and $cond", function () {
+ var result, values, code = '($sequence (set itemId item) (set text (+ (value group) :{hint "objattrs"} ":" item "->" (value value) :{hint "objattrs"})) (set symbol "○") (set color ($cond ((<? (value value) 30) :{hint "compare"} "#3c3" :{format "color"}) ((<? (value value) 60) :{hint "compare"} "#cc3" :{format "color"}) (#t "#c33" :{format "color"}))) (set groupName (value group) :{hint "objattrs"}))';
+
+ result = runCode(code, {
+ "item": "server",
+ "value": {
+ "group": "g1",
+ "value": 59
+ }
+ });
+
+ values = result.bindings;
+
+ Q.equal(values.itemId.value, "server");
+ Q.equal(values.text.value, "g1:server->59");
+ Q.equal(values.symbol.value, "");
+ Q.equal(values.color.value, "#cc3");
+ Q.equal(values.groupName.value, "g1");
+ });
+ };
+
+ return obj;
+}));
View
21 test/squim.test.js
@@ -1,5 +1,4 @@
-/*global define require SquimEnvTest SquimPairTest SquimParserTest
- SquimTypesTest SquimUtilTest SquimModulesTest*/
+/*global define require*/
require.config({
paths: {
@@ -29,21 +28,26 @@ require.config({
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['squim.env.test', 'squim.pair.test', 'squim.parser.test',
- 'squim.types.test', 'squim.util.test', 'squim.modules.test'],
+ 'squim.types.test', 'squim.util.test', 'squim.modules.test',
+ 'snippets.test'],
function (EnvTest, PairTest, ParserTest, TypesTest, UtilTest,
- ModulesTest) {
+ ModulesTest, SnippetsTest) {
// Also create a global in case some scripts
// that are loaded still are looking for
// a global even when an AMD loader is in use.
return (root.SquimTest = factory(EnvTest, PairTest, ParserTest,
- TypesTest, UtilTest, ModulesTest));
+ TypesTest, UtilTest, ModulesTest,
+ SnippetsTest));
});
} else {
// Browser globals
- root.SquimTest = factory(SquimEnvTest, SquimPairTest, SquimParserTest,
- SquimTypesTest, SquimUtilTest, SquimModulesTest);
+ root.SquimTest = factory(root.SquimEnvTest, root.SquimPairTest,
+ root.SquimParserTest, root.SquimTypesTest,
+ root.SquimUtilTest, root.SquimModulesTest,
+ root.SnippetsTest);
}
-}(this, function (EnvTest, PairTest, ParserTest, TypesTest, UtilTest, ModulesTest) {
+}(this, function (EnvTest, PairTest, ParserTest, TypesTest, UtilTest,
+ ModulesTest, SnippetsTest) {
"use strict";
var obj = {};
@@ -54,6 +58,7 @@ require.config({
TypesTest.test();
UtilTest.test();
ModulesTest.test();
+ SnippetsTest.test();
};
obj.test();

No commit comments for this range

Something went wrong with that request. Please try again.