[KSS-checkins] r50411 - in kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes: . kukit tests

reebalazs at codespeak.net reebalazs at codespeak.net
Mon Jan 7 00:17:45 CET 2008


Author: reebalazs
Date: Mon Jan  7 00:17:43 2008
New Revision: 50411

Modified:
   kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/   (props changed)
   kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/kssparser.js
   kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/providerreg.js
   kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/resourcedata.js
   kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/tests/test_kssparser.js
Log:
Adding client action aliasing

Modified: kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/kssparser.js
==============================================================================
--- kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/kssparser.js	(original)
+++ kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/kssparser.js	Mon Jan  7 00:17:43 2008
@@ -236,9 +236,14 @@
     // preprocess values
     var allowedReturnTypes;
 ;;; if (actionType == 'S') {
+;;;     // action-server
 ;;;     allowedReturnTypes = {string: true, formdata: true, url: true};
+;;; } else if (actionType == 'C') {
+;;;     // action-client
+;;;     allowedReturnTypes = {string: true, selection: true, alias: true};
 ;;; } else {
-;;;     allowedReturnTypes = {string: true, selection: true};
+;;;     // action-cancel
+;;;     allowedReturnTypes = {string: true};
 ;;; }
 ;;; kukit.E = 'action definition [' + key + ']';
     var valuesByReturnType = this.preprocessValues(values, allowedReturnTypes, kukit.E);
@@ -425,7 +430,6 @@
     // noStringRequired is set to true at the kss special parameters. All other
     // occasions require at least a string to be present, so we check for that too.
     var valuesByReturnType = {};
-
     for (var i=0; i<values.length; i++) {
         var value = values[i];
         // Checking the value
@@ -440,7 +444,6 @@
         // XXX text values are not wrapped. So we need to check for the
         // pprovider....
         var returnType = (typeof(value.pprovider) != 'undefined') && value.pprovider.returnType;
-        //for(var xx in value) {print (xx, value[xx]);}
         // Default return type is "string".
         if (! returnType) {
             returnType = 'string';

Modified: kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/providerreg.js
==============================================================================
--- kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/providerreg.js	(original)
+++ kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/providerreg.js	Mon Jan  7 00:17:43 2008
@@ -355,7 +355,7 @@
 };
 kukit.pprovidersGlobalRegistry.register('kssIdOfValue', kukit.pr.KssIdOfValuePP);
 
-/* The url() provider just passes the parameters, and is used to have
+/* The url() provider just passes the parameter, and is used to have
  * a different return type. It can be used in the line of action-server.
  * as an alternative to a separate kssUrl line.
  */
@@ -370,3 +370,23 @@
 // returnType = 'url'
 kukit.pprovidersGlobalRegistry.register('url', kukit.pr.UrlPP, 'url');
 
+/* The alias() provider just passes the parameter, and is used to have
+ * a different return type. It can be used in the line of action-client.
+ */
+kukit.pr.AliasPP = function() {
+    this.check = function(args) {
+;;;     if (args.length != 1) {
+;;;         throw new Error('alias() needs 1 argument');
+;;;     }
+;;;     if (args[0].isMethod) {
+;;;         kukit.E = 'Value providers are not ';
+;;;         kukit.E += 'allowed as argument for ';
+;;;         kukit.E += 'alias(), [' + args[0].methodName + '] found.';
+;;;         throw new Error(kukit.E);
+;;;     }
+    };
+};
+kukit.pr.AliasPP.prototype = new kukit.pr.IdentityPP();
+// returnType = 'alias'
+kukit.pprovidersGlobalRegistry.register('alias', kukit.pr.AliasPP, 'alias');
+

Modified: kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/resourcedata.js
==============================================================================
--- kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/resourcedata.js	(original)
+++ kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/resourcedata.js	Mon Jan  7 00:17:43 2008
@@ -518,10 +518,24 @@
 
 kukit.rd.ActionSet.prototype.getOrCreateAction = function(name, valuesByReturnType) {
     // kss parameters will ve set from valuesByReturnType 
+    //
+    // In case we alias, use the alias for name, this will become
+    // the action name used for execution. The alias name will
+    // be used as name, and serve for decide merging.
+    var nameOverride;
+    if (valuesByReturnType.alias) {
+        nameOverride = name;
+        // This is always a string, no provider allowed.
+        // 
+        // XXX atm, strings are unwrapped. (this is fixed
+        // in service-layer branch)
+        name = valuesByReturnType.alias.args[0];
+    }
+    // Check if we have this action already
     var action = this.content[name];
     if (typeof(action) == 'undefined') {
         action = new kukit.rd.Action();
-        action.setName(name);
+        action.setName(name, nameOverride);
         this.content[name] = action;
     }
     // Set other values that were given at the same line as the name.
@@ -573,15 +587,55 @@
     this.error = null;
     this.parms = {};
     this.type = null;
+    this.nameOverride = null;
 };
 
-kukit.rd.Action.prototype.setName = function(name) {
-;;; if (this.name != null && this.name != name) {
-;;;     var msg = 'Error overriding action name [' + this.name;
-;;;     msg = msg + '] to [' + name + '] (Unmatching action names at merge?)';
-;;;     throw kukit.err.ruleMergeError(msg);
+kukit.rd.Action.prototype.getExecutingName = function() {
+    // Returns action name that is to be used for execution.
+    // In case nameOverride is empty, name is used both as merging
+    // key, and for selecting the action at execution.
+    // In case nameOverride is specified, name is still used for
+    // merging, but nameOverride is used when we need to
+    // execute the action.
+    // This is used for  action-client: nameOverride alias(name).
+    return this.nameOverride || this.name;
+};
+
+kukit.rd.Action.prototype.setName = function(name, nameOverride) {
+    if (typeof(nameOverride) == 'undefined' || name == nameOverride) {
+        // use null for no-value.
+        //
+        // Also: If we alias to the same name as the action name,
+        // simply ignore aliasing and just handle the real action.
+        nameOverride = null;
+    }
+;;; // We check that the name did not change.
+;;; if (this.name != null) {
+;;;     if (this.name != name) {
+;;;         kukit.E = 'Error overriding action name [' + this.name;
+;;;         kukit.E += '] to [' + name + '] (Unmatching action names or aliases at merge?)';
+;;;         throw kukit.err.ruleMergeError(kukit.E);
+;;;     }
+;;;     // nameOverride can only be specified when name is also specified.
+;;;     // We also check that the override cannot change, ie. it is not
+;;;     // possible to use the same alias for different actions.
+;;;     // However we allow this.nameOverride to have a value and nameOverride
+;;;     // to be null.
+;;;     if (nameOverride != null && this.nameOverride != nameOverride) {
+;;;         kukit.E = 'Error overriding action name for alias [' + this.name;
+;;;         kukit.E += '] from [' + this.nameOverride;
+;;;         kukit.E += '] to [' + nameOverride + '] ';
+;;;         kukit.E += '(Different actions aliased by the same alias?)';
+;;;         throw kukit.err.ruleMergeError(kukit.E);
+;;;     }
 ;;; }
+    // Store the values.
     this.name = name;
+    // nameOverride is only overwritten if value exists.
+    if (nameOverride != null) {
+        this.nameOverride = nameOverride;
+    }
+    // Handle default action.
     if (name == 'default') {
 ;;;     if (this.type != null && this.type != 'D') {
 ;;;         var msg = 'Error setting action to default on action [' + this.name;
@@ -633,7 +687,8 @@
 kukit.rd.Action.prototype.merge = function(other) {
     // Merge to the instance.
     if (other.name != null) { 
-        this.setName(other.name);
+        // We also use nameOverride from the other.
+        this.setName(other.name, other.nameOverride);
     }
     if (other.type != null) { 
         this.setType(other.type);
@@ -717,7 +772,9 @@
         } break;
         case 'C': {
             // Client action.
-            oper.executeClientAction(this.name);
+            // Need to execute the real name,
+            // since aliasing is possible here.
+            oper.executeClientAction(this.getExecutingName());
         } break;
         case 'E': {
             // Error action (= client action)

Modified: kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/tests/test_kssparser.js
==============================================================================
--- kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/tests/test_kssparser.js	(original)
+++ kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/tests/test_kssparser.js	Mon Jan  7 00:17:43 2008
@@ -294,6 +294,41 @@
         this.assertEquals(parser.values[2].txt, 'oranges');
     };
 
+    this.testMultiPropValueManyProviders = function() {
+        // Multi prop value with many providers
+        var txt= "formVar(x, y) kssAttr(foo, true) formVar(a, b);";
+        var cursor = new kukit.tk.Cursor(txt);
+        var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+        this.assertEquals(parser.finished, true);
+        this.assertEquals(parser.values.length, 3);
+        this.assertEquals(parser.values[0].isMethod, true);
+        this.assertEquals(parser.values[0].methodName, 'formVar');
+        this.assertListEquals(parser.values[0].args, ['x', 'y']);
+        this.assertEquals(parser.values[1].isMethod, true);
+        this.assertEquals(parser.values[1].methodName, 'kssAttr');
+        this.assertListEquals(parser.values[1].args, ['foo', 'true']);
+        this.assertEquals(parser.values[2].isMethod, true);
+        this.assertEquals(parser.values[2].methodName, 'formVar');
+        this.assertListEquals(parser.values[2].args, ['a', 'b']);
+    };
+
+    this.testMultiPropValueStringAndManyProviders = function() {
+        // Multi prop value with a string and many providers
+        var txt= "blah kssAttr(foo, true) formVar(a, b);";
+        var cursor = new kukit.tk.Cursor(txt);
+        var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+        this.assertEquals(parser.finished, true);
+        this.assertEquals(parser.values.length, 3);
+        this.assertEquals(parser.values[0].isMethod, false);
+        this.assertEquals(parser.values[0].txt, 'blah');
+        this.assertEquals(parser.values[1].isMethod, true);
+        this.assertEquals(parser.values[1].methodName, 'kssAttr');
+        this.assertListEquals(parser.values[1].args, ['foo', 'true']);
+        this.assertEquals(parser.values[2].isMethod, true);
+        this.assertEquals(parser.values[2].methodName, 'formVar');
+        this.assertListEquals(parser.values[2].args, ['a', 'b']);
+    };
+
     this.testEventValueSimple = function() {
         // Parsing event value
         var txt= "b";
@@ -955,7 +990,7 @@
         var cursor = new kukit.tk.Cursor(txt);
         this.assertParsingError(kukit.kssp.Document, cursor, null, true,
             // XXX This error message will be fixed in service-layer branch
-            // XXX This will also fix runnin from IE, currently broken at error assert.
+            // XXX This will also fix running from IE, currently broken at error assert.
             'Error in value for action parameter [message] : Error: Expected string value and got [selection] in argument #[1] of provider [nodeAttr].., at row 1, column 11');
     };
 
@@ -987,7 +1022,7 @@
         var cursor = new kukit.tk.Cursor(txt);
         this.assertParsingError(kukit.kssp.Document, cursor, null, true,
             // XXX This error message will be fixed in service-layer branch
-            // XXX This will also fix runnin from IE, currently broken at error assert.
+            // XXX This will also fix running from IE, currently broken at error assert.
             'Error in value for action parameter [message] : Error: Expected string value and got [formdata] in argument #[1] of provider [nodeAttr].., at row 1, column 11');
     };
 
@@ -1004,7 +1039,7 @@
         var cursor = new kukit.tk.Cursor(txt);
         this.assertParsingError(kukit.kssp.Document, cursor, null, true,
             // XXX This error message will be fixed in service-layer branch
-            // XXX This will also fix runnin from IE, currently broken at error assert.
+            // XXX This will also fix running from IE, currently broken at error assert.
             'Missing [string] value in the action parameter [message]., at row 1, column 11');
     };
 
@@ -1021,7 +1056,7 @@
         var cursor = new kukit.tk.Cursor(txt);
         this.assertParsingError(kukit.kssp.Document, cursor, null, true,
             // XXX This error message will be fixed in service-layer branch
-            // XXX This will also fix runnin from IE, currently broken at error assert.
+            // XXX This will also fix running from IE, currently broken at error assert.
             'Provider result type [formdata] not allowed in the action parameter [message]., at row 1, column 1');
     };
 
@@ -1075,7 +1110,7 @@
         var cursor = new kukit.tk.Cursor(txt);
         this.assertParsingError(kukit.kssp.Document, cursor, null, true,
             // XXX This error message will be fixed in service-layer branch
-            // XXX This will also fix runnin from IE, currently broken at error assert.
+            // XXX This will also fix running from IE, currently broken at error assert.
             'Provider result type [formdata] not allowed in the kss action parameter [kssSelector]., at row 1, column 11');
     };
 
@@ -1123,7 +1158,7 @@
         var cursor = new kukit.tk.Cursor(txt);
         this.assertParsingError(kukit.kssp.Document, cursor, null, true,
             // XXX This error message will be fixed in service-layer branch
-            // XXX This will also fix runnin from IE, currently broken at error assert.
+            // XXX This will also fix running from IE, currently broken at error assert.
             'Provider result type [selection] not allowed in the kss action parameter [kssSubmitForm]., at row 1, column 11');
     };
 
@@ -1153,7 +1188,7 @@
         var cursor = new kukit.tk.Cursor(txt);
         this.assertParsingError(kukit.kssp.Document, cursor, null, true,
             // XXX This error message will be fixed in service-layer branch
-            // XXX This will also fix runnin from IE, currently broken at error assert.
+            // XXX This will also fix running from IE, currently broken at error assert.
             'Error in value for action definition [action-client] : Error: form method needs 1 arguments (formname)., at row 1, column 11');
     };
 
@@ -1183,7 +1218,7 @@
         var cursor = new kukit.tk.Cursor(txt);
         this.assertParsingError(kukit.kssp.Document, cursor, null, true,
             // XXX This error message will be fixed in service-layer branch
-            // XXX This will also fix runnin from IE, currently broken at error assert.
+            // XXX This will also fix running from IE, currently broken at error assert.
             'Provider result type [selection] not allowed in the action definition [action-server]., at row 1, column 11');
     };
 
@@ -1242,7 +1277,7 @@
         var cursor = new kukit.tk.Cursor(txt);
         this.assertParsingError(kukit.kssp.Document, cursor, null, true,
             // XXX This error message will be fixed in service-layer branch
-            // XXX This will also fix runnin from IE, currently broken at error assert.
+            // XXX This will also fix running from IE, currently broken at error assert.
             'Missing [string] value in the action definition [action-server]., at row 1, column 11');
     };
 
@@ -1258,7 +1293,7 @@
         var cursor = new kukit.tk.Cursor(txt);
         this.assertParsingError(kukit.kssp.Document, cursor, null, true,
             // XXX This error message will be fixed in service-layer branch
-            // XXX This will also fix runnin from IE, currently broken at error assert.
+            // XXX This will also fix running from IE, currently broken at error assert.
             'Only one [string] value is allowed in the action definition [action-server]., at row 1, column 11');
     };
 
@@ -1276,7 +1311,7 @@
         var cursor = new kukit.tk.Cursor(txt);
         this.assertParsingError(kukit.kssp.Document, cursor, null, true,
             // XXX This error message will be fixed in service-layer branch
-            // XXX This will also fix runnin from IE, currently broken at error assert.
+            // XXX This will also fix running from IE, currently broken at error assert.
             'Error in value for action definition [action-server] : Error: url() needs 1 argument., at row 1, column 11');
     };
 
@@ -1292,7 +1327,7 @@
         var cursor = new kukit.tk.Cursor(txt);
         this.assertParsingError(kukit.kssp.Document, cursor, null, true,
             // XXX This error message will be fixed in service-layer branch
-            // XXX This will also fix runnin from IE, currently broken at error assert.
+            // XXX This will also fix running from IE, currently broken at error assert.
             'Wrong value for key [action-server] : value providers are not allowed for action-<QUALIFIER> keys., at row 1, column 11');
     };
 
@@ -1373,6 +1408,58 @@
         this.assertEquals(parser.finished, true);
     };
 
+    this.testAliasedClientAction = function() {
+        // Client action can be aliased.
+        //
+        // This test can only run in development mode, pass otherwise.
+        // Note that merging the rules is not really tested from here,
+        // as we don't have DOM. So we can't really see if the alias
+        // is working, only that it is parsed well.
+        if (! kukit.isDevelMode) {return;}
+        //
+        var txt= "#id:click {\n"
+               + "    action-client:   doIt alias(doAlias);\n"
+               + "    doAlias-foo:     bar;\n"
+               + "}\n"
+        var cursor = new kukit.tk.Cursor(txt);
+        var parser = new kukit.kssp.Document(cursor, null, true);
+        this.assertEquals(parser.finished, true);
+    };
+
+    this.testServerActionRejectsAlias = function() {
+        // Server action rejects alias().
+        //
+        // This test can only run in development mode, pass otherwise.
+        if (! kukit.isDevelMode) {return;}
+        //
+        var txt= "#id:click {\n"
+               + "    action-server:   doIt alias(doAlias);\n"
+               + "    doAlias-foo:     bar;\n"
+               + "}\n"
+        var cursor = new kukit.tk.Cursor(txt);
+        this.assertParsingError(kukit.kssp.Document, cursor, null, true,
+            // XXX This error message will be fixed in service-layer branch
+            // XXX This will also fix running from IE, currently broken at error assert.
+            'Provider result type [alias] not allowed in the action definition [action-server]., at row 1, column 11');
+    };
+
+    this.testNormalParameterRejectsAlias = function() {
+        // normal parameters do not accept alias.
+        //
+        // This test can only run in development mode, pass otherwise.
+        if (! kukit.isDevelMode) {return;}
+        //
+        var txt= "#id:click {\n"
+               + "    action-client: log;\n"
+               + "    log-message:   whatever alias('name');\n"
+               + "}\n"
+        var cursor = new kukit.tk.Cursor(txt);
+        this.assertParsingError(kukit.kssp.Document, cursor, null, true,
+            // XXX This error message will be fixed in service-layer branch
+            // XXX This will also fix running from IE, currently broken at error assert.
+            'Provider result type [alias] not allowed in the action parameter [message]., at row 1, column 11');
+    };
+
 }; 
 
 kukit.KssParserValueProvidersCheckTestCase.prototype = new kukit.KssParserTestCaseBase;


More information about the Kukit-checkins mailing list