substitute.html revision 0542765205c8bee9c222ae9032c346d12f8c2a5b
Selector:true, Node:true, attribute:true, event:true, base:true, widget:true} }).use("dump", "test", "console", "event-custom", function(Y) {
var button = Y.one('#btnRun'),
Assert = Y.Assert,
ObjectAssert = Y.ObjectAssert;
button.set("disabled", false);
Y.on("click", function() {
var myConsole = new Y.Console().render();
var testSubstitute= new Y.Test.Case({
var param = {domain: 'valvion.com',
media: 'http://media.{domain}/', /* nested */
contextdomain: { context1: 'context{domain}', context2: 'yahoo.com' }, /* the value is an object, we will use a custom function to extract the correct data */
contextmedia: 'http://contextmedia.{contextdomain context1}/'};
return (Y.Lang.isObject(val)) ? val[meta] : val;
Y.substitute("{testobj 0}", { testobj: obj }, null, false),
Y.substitute("{testobj 1}", { testobj: obj }, null, false),
"{level1_1 => 1.1, level1_2 => 1.2, level1_3 => {level2_1 => 2.1, level2_2 => 2.2, level2_3 => {...}, level2_4 => 2.4}, level1_4 => 1.4}",
"{level1_1 => 1.1, level1_2 => 1.2, level1_3 => {level2_1 => 2.1, level2_2 => 2.2, level2_3 => {level3_1 => 3.1, level3_2 => 3.2, level3_3 => 3.3, level3_4 => 3.4}, level2_4 => 2.4}, level1_4 => 1.4}",
Y.substitute("{testarr 1}", { testarr: arr }, null, true),
var result = Y.substitute("{testmix 1}", { testmix: mix }, null, true);
(result.indexOf("GMT" > -1)) ? true : false,
Y.substitute("{customtostr 1}", { customtostr: tostr }, null, true),
// Assert.areEqual(
// Y.substitute("{customtostr dump 1}", { customtostr: tostr }, null, true),
// "{custom1_1 => 1.1, custom1_2 => 1.2, custom1_3 => {custom2_1 => 2.1, custom2_2 => 2.2, custom2_3 => {...}, custom2_4 => 2.4}, custom1_4 => 1.4, toString => f(){...}}",
Assert.areEqual("My last name is Zappa. {I am a replacement string }{}", Y.substitute(template, obj));
Y.Test.Runner.setName("Substitute");
Y.Test.Runner.add(testSubstitute);