Author: ptw
Date: 2007-07-09 19:26:59 -0700 (Mon, 09 Jul 2007)
New Revision: 5636
Added:
openlaszlo/branches/legals/WEB-INF/lps/lfc/compiler/Class.lzs
openlaszlo/branches/legals/WEB-INF/lps/lfc/compiler/Library.lzs
openlaszlo/branches/legals/WEB-INF/lps/lfc/compiler/LzFormatter.lzs
Removed:
openlaszlo/branches/legals/WEB-INF/lps/lfc/core/Class.lzs
Modified:
openlaszlo/branches/legals/WEB-INF/lps/lfc/LaszloLibrary.lzs
openlaszlo/branches/legals/WEB-INF/lps/lfc/core/Library.lzs
openlaszlo/branches/legals/WEB-INF/lps/lfc/debugger/LzFormat.lzs
openlaszlo/branches/legals/WEB-INF/lps/lfc/views/LzText.lzs
openlaszlo/branches/legals/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/Parser.jjt
openlaszlo/branches/legals/test/smoke/lztext.lzl
Log:
Change 20070705-ptw-R by [EMAIL PROTECTED] on 2007-07-05 14:42:10 EDT
in /Users/ptw/OpenLaszlo/legals
for http://svn.openlaszlo.org/openlaszlo/branches/legals
Summary: Move formatToString into LFC
New Features: lz.text has a new method, `format` that implements most
of `printf` for setting the text (content).
Bugs Fixed:
LPP-3073 'Move Format and formatToString from Debug to LFC'
Technical Reviewer: hminsky (Message-ID: <[EMAIL PROTECTED]>)
QA Reviewer: frisco (pending)
Doc Reviewer: jgrandy, jsundman (pending)
Documentation:
Here is an example of using the text `format` method to set the
contents of a text node.
<canvas>
<class name="clickClock" extends="text">
<attribute name="dayTable"
value='["Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"]'
/>
<handler name="onclick">
var now = new Date;
this.format("You clicked me at %02d:%02d:%02d on %s",
now.getHours(),
now.getMinutes(),
now.getSeconds(),
dayTable[now.getDay()]);
</handler>
</class>
<clickClock>
Click Me!
</clickClock>
</canvas>
Release Notes:
Details:
lztext: Duplicated debugger format tests for text
debugger/LzFormat, compiler/LzFormatter: moved pad and
formatToString out of debugger into compiler as a mixin.
core/Library: moved class support to compiler.
LzText: mix in LzFormatter, add format method.
LaszloLibrary, compiler/Library: compiler runtime support is 3
files now: runtime, class, and formatter.
Parser.jjt: add `mixin` as an alias for `trait` and `with` as an
alias for `inherits`. This will allow us to transition to the new
approved syntax for mixins.
Tests:
ant lztest, smokecheck
Modified: openlaszlo/branches/legals/WEB-INF/lps/lfc/LaszloLibrary.lzs
===================================================================
--- openlaszlo/branches/legals/WEB-INF/lps/lfc/LaszloLibrary.lzs
2007-07-10 00:35:11 UTC (rev 5635)
+++ openlaszlo/branches/legals/WEB-INF/lps/lfc/LaszloLibrary.lzs
2007-07-10 02:26:59 UTC (rev 5636)
@@ -3,7 +3,7 @@
/**
* Definition of the basic LFC Library
*
- * @copyright Copyright 2001-2006 Laszlo Systems, Inc. All Rights Reserved.
+ * @copyright Copyright 2001-2007 Laszlo Systems, Inc. All Rights Reserved.
* Use is subject to license terms.
*
* @access private
@@ -13,7 +13,7 @@
var _Copyright = "Portions of this file are copyright (c) 2001-2007 by Laszlo
Systems, Inc. All rights reserved.";
// Compiler runtime support first
-#include "compiler/LzRuntime.lzs"
+#include "compiler/Library.lzs"
if ($debug) {
// Must be loaded second
Copied: openlaszlo/branches/legals/WEB-INF/lps/lfc/compiler/Class.lzs (from rev
5579, openlaszlo/branches/legals/WEB-INF/lps/lfc/core/Class.lzs)
Added: openlaszlo/branches/legals/WEB-INF/lps/lfc/compiler/Library.lzs
Property changes on:
openlaszlo/branches/legals/WEB-INF/lps/lfc/compiler/Library.lzs
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: openlaszlo/branches/legals/WEB-INF/lps/lfc/compiler/LzFormatter.lzs
Property changes on:
openlaszlo/branches/legals/WEB-INF/lps/lfc/compiler/LzFormatter.lzs
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Deleted: openlaszlo/branches/legals/WEB-INF/lps/lfc/core/Class.lzs
Modified: openlaszlo/branches/legals/WEB-INF/lps/lfc/core/Library.lzs
===================================================================
--- openlaszlo/branches/legals/WEB-INF/lps/lfc/core/Library.lzs 2007-07-10
00:35:11 UTC (rev 5635)
+++ openlaszlo/branches/legals/WEB-INF/lps/lfc/core/Library.lzs 2007-07-10
02:26:59 UTC (rev 5636)
@@ -1,7 +1,7 @@
/**
* Library.lzs
*
- * @copyright Copyright 2001-2006 Laszlo Systems, Inc. All Rights Reserved.
+ * @copyright Copyright 2001-2007 Laszlo Systems, Inc. All Rights Reserved.
* Use is subject to license terms.
*
* @access private
@@ -9,6 +9,5 @@
#include "core/LzConstants.lzs"
#include "core/LzDefs.lzs"
-#include "core/Class.lzs"
#include "core/LzNode.lzs"
#include "core/UserClass.lzs"
Modified: openlaszlo/branches/legals/WEB-INF/lps/lfc/debugger/LzFormat.lzs
===================================================================
--- openlaszlo/branches/legals/WEB-INF/lps/lfc/debugger/LzFormat.lzs
2007-07-10 00:35:11 UTC (rev 5635)
+++ openlaszlo/branches/legals/WEB-INF/lps/lfc/debugger/LzFormat.lzs
2007-07-10 02:26:59 UTC (rev 5636)
@@ -100,365 +100,20 @@
* Formatted output for the Laszlo Debugger
*/
-// Stolen from components/utils/performance/measure.lzx, but much
-// improved since then!
-/**
- * pad or trim a string to a specified length
- * @param str: the value to pad, will be coerced to a string if not a number
- * @param Number len: the minimum width, if negative pad on the right
- * @param Number dec: for numbers: ensure dec characters to the right
- * of '.', padding with 0, otherwise maximum width
- * @param String pad: character to pad on left with, default ' '
- * @param String sign: ' ', '-', '+', default '-'
- * @param Number radix: radix to represent numbers in, default 10
- * @param Boolean force: ensure numbers always have a decimal
- */
-Debug.pad = function (str, len, dec, pad, sign, radix, force) {
- switch (arguments.length) {
- case 0:
- str = '';
- case 1:
- len = null;
- case 2:
- dec = null;
- case 3:
- pad = ' ';
- case 4:
- sign = '-';
- case 5:
- radix = 10;
- case 6:
- force = false;
- }
- var num = typeof(str) == 'number';
- // coerce to be string
- if (num) {
- if (dec != null) {
- var precision = Math.pow(10, (- dec));
- str = Math.round(str/precision)*precision;
- }
- str = Number(str).toString(radix);
- if (sign != '-') {
- if (str.indexOf('-') != 0) {
- if (str != 0) {
- str = sign + str;
- } else {
- // ' 0' not '+0'
- str = ' ' + str;
- }
- }
- }
- } else {
- str = '' + str;
- }
- var strlen = str.length;
- // enforce precision
- if (dec != null) {
- if (num) {
- var decimal = str.lastIndexOf('.');
- if (decimal == -1) {
- var decimals = 0;
- if (force || (dec > 0)) {
- str += '.';
- }
- } else {
- var decimals = strlen - (decimal + 1);
- }
- for (var i = decimals; i < dec; i++) str += '0';
- } else {
- str = str.substring(0, dec);
- }
- }
- // enforce minimum width
- strlen = str.length;
- if (! len) {
- len = 0;
- }
- var left = false;
- if (len < 0) {
- len = (- len);
- left = true;
- }
- if (strlen >= len) {
- return str;
- }
- if (left) {
- for (var i = strlen; i < len; i++) str = str + ' ';
- } else {
- sign = null;
- if (pad != ' ') {
- // Need to move sign to left of padding
- if (" +-".indexOf(str.substring(0, 1)) >= 0) {
- sign = str.substring(0, 1);
- str = str.substring(1);
- }
- }
- for (var i = strlen; i < len; i++) str = pad + str;
- if (sign != null) {
- str = sign + str;
- }
- }
- return str;
-}
+/* TODO: [2007-07-05 ptw] When the debugger is 'classified'
+ * these can be acquired through the LzFormatter mixin
+ */
+Debug.pad = LzFormatter.prototype.pad;
+Debug.formatToString = LzFormatter.prototype.formatToString;
/**
- * Formatted output to string
- * Formats its arguments according to the control string
- *
- * The standard printf conversions are accepted, with the exception of
- * `a`, `n`, and `p`. `e`, `f`, and `g` conversions are accepted but
- * equivalent to `f`. The `h` and `l` length modifiers are accepted
- * but ignored. No errors are signalled for invalid format controls
- * or insufficient arguments.
- *
- * There is an additional format specifier `w` that formats the
- * argument as if by `Debug.__String` with the 'pretty' option and
- * creates a 'hotlink' so the object can be inspected. If alternate
- * format is requested (#), `w` uses the full `Debug.__String` format
- * used by <xref linkend="Debug+debug.write"/>. `%w` format obeys <xref
linkend="Debug+debug.printLength"/>. If a
- * precision is specified, that is used as printLength.
- *
- * @param string control: A control string where % indicates a
- * subsequent argument is to be substituted.
- *
- * @param any... args: arguments to be formatted according to the
- * control string.
- *
- * @return LzMessage: the return value is an LzMessage which can be
- * coreced to a string or HTML (the latter supports the hot-linking
- * feature).
- *
- * @devnote For backwards compatibility with <xref
linkend="Debug+debug.write"/>, if control is not a
- * string or control has no formatting directives but there are
- * multiple arguments, all the arguments are emitted separated by
- * spaces.
- */
-Debug.formatToString = function (control, args) {
- var al = arguments.length;
- // 'write compatibility mode': control is not a string or # of
- // arguments is incompatible with control directives.
- if ((! (typeof control == 'string' || control instanceof String)) ||
- ((al > 1) != (control.indexOf('%') >= 0))) {
- // Process each value to individually so they can be
- // 'presented' as objects if applicable
- var out = new LzMessage;
- for (var i = 0; i < al; i++) {
- var arg = arguments[i];
- var sep = ((i == (al-1)) ? '\n' : ' ');
- out.append(arg);
- // separator is always pretty
- out.appendInternal(sep);
- }
- return out;
- }
- // Normal mode
- if (al < 1) { control = '' };
- var ctrl = '' + control;
- // skip control
- var argno = 1;
- var arglist = arguments;
- function getarg(i) {
- if (i >= al) {
- Debug.warn("%#0.48w: insufficient arguments", control);
- return null;
- }
- return arglist[i];
- }
- var base = 0, limit = ctrl.length;
- var start = 0, end = 0;
- var out = new LzMessage();
- while (start < limit) {
- end = ctrl.indexOf('%');
- if (end == -1) {
- out.append(ctrl.substring(start, limit));
- break;
- }
- out.append(ctrl.substring(start, end));
- // skip %
- base = end;
- start = end + 1;
- end = end + 2;
- var sign = '-';
- var pad = ' ';
- var alternate = false;
- var length = '';
- var precision = null;
- var directive = null;
- while ((start < limit) &&
- // swf7 (! directive)
- (directive == null)) {
- var char = ctrl.substring(start, end);
- start = end++;
- // This is a little sloppy. It will parse valid options,
- // but also permits invalid ones, whose behaviour is
- // undefined.
- switch (char) {
- case '-': length = char; break;
- case '+': case ' ':
- sign = char;
- break;
- case '#': alternate = true; break;
- case '0':
- if (length === '' && precision === null) {
- pad = char; break;
- }
- case '1': case '2': case '3': case '4': case '5':
- case '6': case '7': case '8': case '9':
- if (precision !== null) {
- precision += char;
- } else {
- length += char;
- }
- break;
- case '$':
- argno = length;
- length = '';
- break;
- case '*':
- if (precision !== null) {
- precision = getarg(argno);
- argno++;
- } else {
- length = getarg(argno);
- argno++;
- }
- break;
- case '.': precision = ''; break;
- case 'h': case 'l': break;
- default:
- directive = char;
- break;
- }
- }
- var value = getarg(argno);
- // set decimals
- var decimals = null;
- var force = false;
- // NOTE: [2006-11-17 ptw] Number("010") -> 8 in swf, 10 in ECMA,
- // hence use null/'' as flag not ''/'0'
- if (precision !== null) {
- decimals = 1 * precision;
- } else {
- switch (directive) {
- case 'F': case 'E': case 'G':
- case 'f': case 'e': case 'g':
- decimals = 6;
- force = alternate;
- break;
- case 'O': case 'o':
- if (alternate && value != 0) {
- out.append('0');
- }
- break;
- case 'X': case 'x':
- if (alternate && value != 0) {
- out.append('0' + directive);
- }
- break;
- }
- }
- // set radix
- var radix = 10;
- switch (directive) {
- case 'o': case 'O':
- radix = 8; break;
- case 'x': case'X':
- radix = 16; break;
- }
-// Debug.write('directive', directive, 'value', value, 'length', length,
-// 'decimals', decimals, 'pad', pad, 'sign', sign, 'radix',
radix);
- // 'unsigned'
- switch (directive) {
- case 'U': case 'O': case 'X':
- case 'u': case 'o': case 'x':
- if (value < 0) {
- value = (- value);
- // NOTE: [2006-11-17 ptw] Number('') -> NaN in swf, 0 in
- // ECMA, hence use parseInt
- var wid = Math.abs(parseInt(length));
- if (isNaN(wid)) {
- wid = Number(value).toString(radix).length;
- }
- var max = Math.pow(radix, wid);
- value = max - value;
- }
- }
-// Debug.write('directive', directive, 'value', value, 'length', length,
-// 'decimals', decimals, 'pad', pad, 'sign', sign, 'radix',
radix);
- // do the directive
- // e, f, and, g could be implemented with toExponential or
- // toPrecision if they existed in the runtime.
- switch (directive) {
- case 'D': case 'U': case 'I': case 'O': case 'X': case 'F': case 'E':
case 'G':
- value = Number(value);
- out.append(this.pad(value, length, decimals, pad, sign, radix,
force).toUpperCase());
- argno++; // consume value
- break;
- case 'c':
- value = String.fromCharCode(value);
- case 's':
- // TODO: [2006-06-01 ptw] Generalize this to write 'pretty'
- // values for all
- var str;
- if (value instanceof Function) {
- str = Debug.functionName(value) || 'function () {...}';
- } else if (typeof value == 'number') {
- // Must convert number to string for proper padding
- str = Number(value).toString(radix);
- } else {
- str = '' + value;
- }
- out.appendInternal(this.pad(str, length, decimals, pad, sign, radix,
force),
- value);
- argno++; // consume value
- break;
- case 'd': case 'u': case 'i': case 'o': case 'x': case 'f': case 'e':
case 'g':
- value = Number(value);
- out.append(this.pad(value, length, decimals, pad, sign, radix, force));
- argno++; // consume value
- break;
- case 'w':
- var width = decimals || this.printLength;
- out.appendInternal(this.pad(this.__String(value, (! alternate), width),
- length, null, pad, sign, radix, force),
- value);
- argno++; // consume value
- break;
- case '%':
- out.append('%');
- break;
- default:
- // treat unknown directive as literal
- out.append(ctrl.substring(base, start));
- break;
- }
- ctrl = ctrl.substring(start, limit);
- base = 0, limit = ctrl.length;
- start = 0, end = 0;
- }
- if (argno < al) {
- this.warn("%#0.48w: excess arguments", control);
- // Output excess in 'write compatibility' mode
- out.appendInternal(' ');
- for (; argno < al; argno++) {
- var arg = getarg(argno);
- var sep = ((argno == (al-1)) ? '\n' : ' ');
- out.append(arg);
- out.appendInternal(sep);
- }
- }
-
- return out;
-}
-
-/**
* Formatted output.
- * Formats its arguments using <xref linkend="Debug+debug.formatToString"/>.
- *
+ * Formats its arguments using <xref linkend="LzFormatter.formatToString"/>.
+ *
* @param string control: A control string where % indicates a
* subsequent argument is to be substituted
- *
- * @param any... args: arguments to be formatted according to the
+ *
+ * @param *... args: arguments to be formatted according to the
* control string
*/
Modified: openlaszlo/branches/legals/WEB-INF/lps/lfc/views/LzText.lzs
===================================================================
--- openlaszlo/branches/legals/WEB-INF/lps/lfc/views/LzText.lzs 2007-07-10
00:35:11 UTC (rev 5635)
+++ openlaszlo/branches/legals/WEB-INF/lps/lfc/views/LzText.lzs 2007-07-10
02:26:59 UTC (rev 5636)
@@ -71,7 +71,7 @@
* supplied, the text field will by default be sized to fit the width of
* the initial text value.
*/
-class LzText extends LzView {
+class LzText extends LzView with LzFormatter {
/** @access private
* @modifiers override
@@ -669,6 +669,22 @@
}
/**
+ * Formatted output.
+ * Formats its arguments using <xref
+ * linkend="LzFormatter.formatToString"/> and sets the text of the
+ * view to the result.
+ *
+ * @param string control: A control string where % indicates a
+ * subsequent argument is to be substituted
+ *
+ * @param *... args: arguments to be formatted according to the
+ * control string
+ */
+function format (control, args) {
+ this.setText(this.formatToString.apply(this, arguments));
+}
+
+/**
* This must be called after updating the measurement. This is done for speed.
*
* @access private
Modified:
openlaszlo/branches/legals/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/Parser.jjt
===================================================================
---
openlaszlo/branches/legals/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/Parser.jjt
2007-07-10 00:35:11 UTC (rev 5635)
+++
openlaszlo/branches/legals/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/Parser.jjt
2007-07-10 02:26:59 UTC (rev 5636)
@@ -184,6 +184,7 @@
| < STATIC: "static" >
| < SUPER: "super" >
| < TRAIT: "trait" >
+| < MIXIN: "mixin" >
// These are not supposed to be keywords
| < TRUE: "true" >
@@ -358,8 +359,10 @@
| "extends" {jjtThis.setName("extends");}
| "implements" {jjtThis.setName("implements");}
| "inherits" {jjtThis.setName("inherits");}
+| "with" {jjtThis.setName("with");}
| "interface" {jjtThis.setName("interface");}
| "trait" {jjtThis.setName("trait");}
+| "mixin" {jjtThis.setName("mixin");}
}
@@ -883,6 +886,7 @@
{
"class" {jjtThis.setName("class");}
| "trait" {jjtThis.setName("trait");}
+| "mixin" {jjtThis.setName("trait");}
}
void ClassDirective() #void : {}
@@ -913,7 +917,7 @@
ClassOrTrait() Identifier()
["extends" Identifier() ] #EmptyExpression(jjtree.nodeArity()==0)
- ["inherits" TraitsList() ] #EmptyExpression(jjtree.nodeArity()==0)
+ [("inherits" | "with" ) TraitsList() ]
#EmptyExpression(jjtree.nodeArity()==0)
"{" (
ClassDirective()
)* "}"
Modified: openlaszlo/branches/legals/test/smoke/lztext.lzl
===================================================================
--- openlaszlo/branches/legals/test/smoke/lztext.lzl 2007-07-10 00:35:11 UTC
(rev 5635)
+++ openlaszlo/branches/legals/test/smoke/lztext.lzl 2007-07-10 02:26:59 UTC
(rev 5636)
@@ -4,21 +4,227 @@
* Use is subject to license terms. *
* X_LZ_COPYRIGHT_END ****************************************************** -->
<class name="LzTextTest" extends="TestCase">
+ <method name="setUp">
+ <![CDATA[
+ this.date = new Date(Date.UTC(1969, 6, 20, 20, 17, 40, 0));
+ this.dateString = this.date.toString();
+ this.array = [1, 2, 3];
+ this.object = {one: 1, two: 'too', 3: 'three'};
+ this.testString = '"String", with \'\\\' escapes';
+ ]]>
+ </method>
+
+ <method name="tearDown">
+ </method>
+
<method name="testInputText">
- // must be multiline for multiline getText() to work in DHTML
+ // must be multiline for multiline getText() to work in DHTML
var inp = new LzInputText(canvas, {x: 100, y: 100, width: 200, multiline:
true});
inp.setText("foo\n\nbar");
// test getText() not eating newlines
if ($dhtml) {
- assertEquals("foo\n\nbar", inp.getText());
+ assertEquals("foo\n\nbar", inp.getText());
inp.setText(inp.getText() + "\nbaz\nfoo whitespace\nbar.");
assertEquals("foo\n\nbar\nbaz\nfoo whitespace\nbar.",
inp.getText());
} else {
// SWF returns \r instead of \n...
- assertEquals("foo\r\rbar", inp.getText());
+ assertEquals("foo\r\rbar", inp.getText());
inp.setText(inp.getText() + "\nbaz\nfoo whitespace\nbar.");
assertEquals("foo\r\rbar\rbaz\rfoo whitespace\rbar.",
inp.getText());
}
</method>
+
+ <text id="textFormatTest">
+ This is some text.
+ </text>
+
+ <!-- Note this duplicates the debugger format tests, but ensures
formatting works correctly in text -->
+ <method name="testTextFormat">
+ <![CDATA[
+ // The commented out tests can't be run because they
+ // print object ID's which can't be compared easily.
+ // Maybe someday lzunit will have a regexp compare
+ assertEquals(' 3.14', (textFormatTest.format('%8.2f',
Math.PI), textFormatTest.text));
+ assertEquals(' 0.00', (textFormatTest.format('%8.2f', 0),
textFormatTest.text));
+ assertEquals(' -3.14', (textFormatTest.format('%8.2f',
-Math.PI), textFormatTest.text));
+ assertEquals('00003.14', (textFormatTest.format('%08.2f',
Math.PI), textFormatTest.text));
+ assertEquals('00000.00', (textFormatTest.format('%08.2f', 0),
textFormatTest.text));
+ assertEquals('-0003.14', (textFormatTest.format('%08.2f',
-Math.PI), textFormatTest.text));
+ assertEquals(' +3.14', (textFormatTest.format('%+8.2f',
Math.PI), textFormatTest.text));
+ assertEquals(' 0.00', (textFormatTest.format('%+8.2f', 0),
textFormatTest.text));
+ assertEquals(' -3.14', (textFormatTest.format('%+8.2f',
-Math.PI), textFormatTest.text));
+ assertEquals('+0003.14', (textFormatTest.format('%+08.2f',
Math.PI), textFormatTest.text));
+ assertEquals(' 0000.00', (textFormatTest.format('%+08.2f', 0),
textFormatTest.text));
+ assertEquals('-0003.14', (textFormatTest.format('%+08.2f',
-Math.PI), textFormatTest.text));
+ assertEquals(' 3.14', (textFormatTest.format('% 8.2f',
Math.PI), textFormatTest.text));
+ assertEquals(' 0.00', (textFormatTest.format('% 8.2f', 0),
textFormatTest.text));
+ assertEquals(' -3.14', (textFormatTest.format('% 8.2f',
-Math.PI), textFormatTest.text));
+ assertEquals(' 0003.14', (textFormatTest.format('% 08.2f',
Math.PI), textFormatTest.text));
+ assertEquals(' 0000.00', (textFormatTest.format('% 08.2f', 0),
textFormatTest.text));
+ assertEquals('-0003.14', (textFormatTest.format('% 08.2f',
-Math.PI), textFormatTest.text));
+ assertEquals('3.14 ', (textFormatTest.format('%-8.2f',
Math.PI), textFormatTest.text));
+ assertEquals('0.00 ', (textFormatTest.format('%-8.2f', 0),
textFormatTest.text));
+ assertEquals('-3.14 ', (textFormatTest.format('%-8.2f',
-Math.PI), textFormatTest.text));
+ assertEquals('3.14 ', (textFormatTest.format('%-08.2f',
Math.PI), textFormatTest.text));
+ assertEquals('0.00 ', (textFormatTest.format('%-08.2f', 0),
textFormatTest.text));
+ assertEquals('-3.14 ', (textFormatTest.format('%-08.2f',
-Math.PI), textFormatTest.text));
+ assertEquals('+3.14 ', (textFormatTest.format('%-+8.2f',
Math.PI), textFormatTest.text));
+ assertEquals(' 0.00 ', (textFormatTest.format('%-+8.2f', 0),
textFormatTest.text));
+ assertEquals('-3.14 ', (textFormatTest.format('%-+8.2f',
-Math.PI), textFormatTest.text));
+ assertEquals('+3.14 ', (textFormatTest.format('%-+08.2f',
Math.PI), textFormatTest.text));
+ assertEquals(' 0.00 ', (textFormatTest.format('%-+08.2f', 0),
textFormatTest.text));
+ assertEquals('-3.14 ', (textFormatTest.format('%-+08.2f',
-Math.PI), textFormatTest.text));
+ assertEquals(' 3.14 ', (textFormatTest.format('%- 8.2f',
Math.PI), textFormatTest.text));
+ assertEquals(' 0.00 ', (textFormatTest.format('%- 8.2f', 0),
textFormatTest.text));
+ assertEquals('-3.14 ', (textFormatTest.format('%- 8.2f',
-Math.PI), textFormatTest.text));
+ assertEquals(' 3.14 ', (textFormatTest.format('%- 08.2f',
Math.PI), textFormatTest.text));
+ assertEquals(' 0.00 ', (textFormatTest.format('%- 08.2f', 0),
textFormatTest.text));
+ assertEquals('-3.14 ', (textFormatTest.format('%- 08.2f',
-Math.PI), textFormatTest.text));
+ assertEquals('42 ', (textFormatTest.format('%-07d', 42),
textFormatTest.text));
+ assertEquals('2A', (textFormatTest.format('%X', 42),
textFormatTest.text));
+ assertEquals('2a ', (textFormatTest.format('%-07x', 42),
textFormatTest.text));
+ assertEquals('0X2A', (textFormatTest.format('%#X', 42),
textFormatTest.text));
+ assertEquals('0x2a ', (textFormatTest.format('%-07#x', 42),
textFormatTest.text));
+ assertEquals('-42 ', (textFormatTest.format('%-07d', -42),
textFormatTest.text));
+ assertEquals('D6', (textFormatTest.format('%X', -42),
textFormatTest.text));
+ assertEquals('fffffd6', (textFormatTest.format('%-07x', -42),
textFormatTest.text));
+ assertEquals('0XD6', (textFormatTest.format('%#X', -42),
textFormatTest.text));
+ assertEquals('0xfffffd6', (textFormatTest.format('%-07#x',
-42), textFormatTest.text));
+ // %d on string (e.g., array index)
+ assertEquals('42 ', (textFormatTest.format('%-07d', '42'),
textFormatTest.text));
+ assertEquals('2A', (textFormatTest.format('%X', '42'),
textFormatTest.text));
+ assertEquals('2a ', (textFormatTest.format('%-07x', '42'),
textFormatTest.text));
+ assertEquals('0X2A', (textFormatTest.format('%#X', '42'),
textFormatTest.text));
+ assertEquals('0x2a ', (textFormatTest.format('%-07#x',
'42'), textFormatTest.text));
+ assertEquals('-42 ', (textFormatTest.format('%-07d', '-42'),
textFormatTest.text));
+ assertEquals('D6', (textFormatTest.format('%X', '-42'),
textFormatTest.text));
+ assertEquals('fffffd6', (textFormatTest.format('%-07x', '-42'),
textFormatTest.text));
+ assertEquals('0XD6', (textFormatTest.format('%#X', '-42'),
textFormatTest.text));
+ assertEquals('0xfffffd6', (textFormatTest.format('%-07#x',
'-42'), textFormatTest.text));
+ assertEquals('Hello Laszlo!', (textFormatTest.format('%s',
"Hello Laszlo!"), textFormatTest.text));
+ assertEquals("'Hello Laszlo!'", (textFormatTest.format('%w',
"Hello Laszlo!"), textFormatTest.text));
+ assertEquals('Hello', (textFormatTest.format('%.5s', "Hello
Laszlo!"), textFormatTest.text));
+ // non numeric
+ assertEquals('NaN ', (textFormatTest.format('%-07d',
'forty-two'), textFormatTest.text));
+// assertEquals('Hello', (textFormatTest.format('%.5w', "Hello
Laszlo!"), textFormatTest.text));
+ assertEquals(' Hello Laszlo!',
(textFormatTest.format('%30s', "Hello Laszlo!"), textFormatTest.text));
+ assertEquals(" 'Hello Laszlo!'",
(textFormatTest.format('%30w', "Hello Laszlo!"), textFormatTest.text));
+ assertEquals(' Hello',
(textFormatTest.format('%30.5s', "Hello Laszlo!"), textFormatTest.text));
+// assertEquals(' Hello',
(textFormatTest.format('%30.5w', "Hello Laszlo!"), textFormatTest.text));
+ assertEquals('Hello Laszlo!', (textFormatTest.format('%-s',
"Hello Laszlo!"), textFormatTest.text));
+ assertEquals("'Hello Laszlo!'", (textFormatTest.format('%-w',
"Hello Laszlo!"), textFormatTest.text));
+ assertEquals('Hello', (textFormatTest.format('%-.5s', "Hello
Laszlo!"), textFormatTest.text));
+// assertEquals('Hello', (textFormatTest.format('%-.5w', "Hello
Laszlo!"), textFormatTest.text));
+ assertEquals('Hello Laszlo! ',
(textFormatTest.format('%-30s', "Hello Laszlo!"), textFormatTest.text));
+ assertEquals("'Hello Laszlo!' ",
(textFormatTest.format('%-30w', "Hello Laszlo!"), textFormatTest.text));
+ assertEquals('Hello ',
(textFormatTest.format('%-30.5s', "Hello Laszlo!"), textFormatTest.text));
+// assertEquals('Hello ',
(textFormatTest.format('%-30.5w', "Hello Laszlo!"), textFormatTest.text));
+ assertEquals('1,2,3', (textFormatTest.format('%s', this.array),
textFormatTest.text));
+ assertEquals('[1, 2, 3]', (textFormatTest.format('%w',
this.array), textFormatTest.text));
+ assertEquals('1,2,3', (textFormatTest.format('%.5s',
this.array), textFormatTest.text));
+// assertEquals('[1, 2', (textFormatTest.format('%.5w',
this.array), textFormatTest.text));
+ assertEquals(' 1,2,3',
(textFormatTest.format('%30s', this.array), textFormatTest.text));
+ assertEquals(' [1, 2, 3]',
(textFormatTest.format('%30w', this.array), textFormatTest.text));
+ assertEquals(' 1,2,3',
(textFormatTest.format('%30.5s', this.array), textFormatTest.text));
+// assertEquals(' [1, 2',
(textFormatTest.format('%30.5w', this.array), textFormatTest.text));
+ assertEquals('1,2,3', (textFormatTest.format('%-s',
this.array), textFormatTest.text));
+ assertEquals('[1, 2, 3]', (textFormatTest.format('%-w',
this.array), textFormatTest.text));
+ assertEquals('1,2,3', (textFormatTest.format('%-.5s',
this.array), textFormatTest.text));
+// assertEquals('[1, 2', (textFormatTest.format('%-.5w',
this.array), textFormatTest.text));
+ assertEquals('1,2,3 ',
(textFormatTest.format('%-30s', this.array), textFormatTest.text));
+ assertEquals('[1, 2, 3] ',
(textFormatTest.format('%-30w', this.array), textFormatTest.text));
+ assertEquals('1,2,3 ',
(textFormatTest.format('%-30.5s', this.array), textFormatTest.text));
+// assertEquals('[1, 2 ',
(textFormatTest.format('%-30.5w', this.array), textFormatTest.text));
+ assertEquals('[object Object]', (textFormatTest.format('%s',
this.object), textFormatTest.text));
+ assertEquals('{one: 1, two: too, 3: three}',
(textFormatTest.format('%w', this.object), textFormatTest.text));
+ assertEquals('[obje', (textFormatTest.format('%.5s',
this.object), textFormatTest.text));
+// assertEquals('{one:', (textFormatTest.format('%.5w',
this.object), textFormatTest.text));
+ assertEquals(' [object Object]',
(textFormatTest.format('%30s', this.object), textFormatTest.text));
+ assertEquals(' {one: 1, two: too, 3: three}',
(textFormatTest.format('%30w', this.object), textFormatTest.text));
+ assertEquals(' [obje',
(textFormatTest.format('%30.5s', this.object), textFormatTest.text));
+// assertEquals(' {one:',
(textFormatTest.format('%30.5w', this.object), textFormatTest.text));
+ assertEquals('[object Object]', (textFormatTest.format('%-s',
this.object), textFormatTest.text));
+ assertEquals('{one: 1, two: too, 3: three}',
(textFormatTest.format('%-w', this.object), textFormatTest.text));
+ assertEquals('[obje', (textFormatTest.format('%-.5s',
this.object), textFormatTest.text));
+// assertEquals('{one:', (textFormatTest.format('%-.5w',
this.object), textFormatTest.text));
+ assertEquals('[object Object] ',
(textFormatTest.format('%-30s', this.object), textFormatTest.text));
+ assertEquals('{one: 1, two: too, 3: three} ',
(textFormatTest.format('%-30w', this.object), textFormatTest.text));
+ assertEquals('[obje ',
(textFormatTest.format('%-30.5s', this.object), textFormatTest.text));
+// assertEquals('{one: ',
(textFormatTest.format('%-30.5w', this.object), textFormatTest.text));
+ assertEquals('true', (textFormatTest.format('%s', true),
textFormatTest.text));
+ assertEquals('true', (textFormatTest.format('%w', true),
textFormatTest.text));
+ assertEquals('true', (textFormatTest.format('%.5s', true),
textFormatTest.text));
+ assertEquals('true', (textFormatTest.format('%.5w', true),
textFormatTest.text));
+ assertEquals(' true',
(textFormatTest.format('%30s', true), textFormatTest.text));
+ assertEquals(' true',
(textFormatTest.format('%30w', true), textFormatTest.text));
+ assertEquals(' true',
(textFormatTest.format('%30.5s', true), textFormatTest.text));
+ assertEquals(' true',
(textFormatTest.format('%30.5w', true), textFormatTest.text));
+ assertEquals('true', (textFormatTest.format('%-s', true),
textFormatTest.text));
+ assertEquals('true', (textFormatTest.format('%-w', true),
textFormatTest.text));
+ assertEquals('true', (textFormatTest.format('%-.5s', true),
textFormatTest.text));
+ assertEquals('true', (textFormatTest.format('%-.5w', true),
textFormatTest.text));
+ assertEquals('true ',
(textFormatTest.format('%-30s', true), textFormatTest.text));
+ assertEquals('true ',
(textFormatTest.format('%-30w', true), textFormatTest.text));
+ assertEquals('true ',
(textFormatTest.format('%-30.5s', true), textFormatTest.text));
+ assertEquals('true ',
(textFormatTest.format('%-30.5w', true), textFormatTest.text));
+ assertEquals('"String", with \'\\\' escapes',
(textFormatTest.format('%s', this.testString), textFormatTest.text));
+ assertEquals("'\"String\", with \\'\\\\\\' escapes'",
(textFormatTest.format('%w', this.testString), textFormatTest.text));
+ assertEquals('"Stri', (textFormatTest.format('%.5s',
this.testString), textFormatTest.text));
+// assertEquals('"Stri', (textFormatTest.format('%.5w',
this.testString), textFormatTest.text));
+ assertEquals(' "String", with \'\\\' escapes',
(textFormatTest.format('%30s', this.testString), textFormatTest.text));
+ assertEquals("'\"String\", with \\'\\\\\\' escapes'",
(textFormatTest.format('%30w', this.testString), textFormatTest.text));
+ assertEquals(' "Stri',
(textFormatTest.format('%30.5s', this.testString), textFormatTest.text));
+// assertEquals(' "Stri',
(textFormatTest.format('%30.5w', this.testString), textFormatTest.text));
+ assertEquals('"String", with \'\\\' escapes',
(textFormatTest.format('%-s', this.testString), textFormatTest.text));
+ assertEquals("'\"String\", with \\'\\\\\\' escapes'",
(textFormatTest.format('%-w', this.testString), textFormatTest.text));
+ assertEquals('"Stri', (textFormatTest.format('%-.5s',
this.testString), textFormatTest.text));
+// assertEquals('"Stri', (textFormatTest.format('%-.5w',
this.testString), textFormatTest.text));
+ assertEquals('"String", with \'\\\' escapes ',
(textFormatTest.format('%-30s', this.testString), textFormatTest.text));
+ assertEquals("'\"String\", with \\'\\\\\\' escapes'",
(textFormatTest.format('%-30w', this.testString), textFormatTest.text));
+ assertEquals('"Stri ',
(textFormatTest.format('%-30.5s', this.testString), textFormatTest.text));
+// assertEquals('"Stri ',
(textFormatTest.format('%-30.5w', this.testString), textFormatTest.text));
+ assertEquals(this.dateString, (textFormatTest.format('%s',
this.date), textFormatTest.text));
+ assertEquals(this.dateString, (textFormatTest.format('%w',
this.date), textFormatTest.text));
+ assertEquals(this.dateString.substring(0, 5),
(textFormatTest.format('%.5s', this.date), textFormatTest.text));
+// assertEquals(this.dateString.substring(0, 5),
(textFormatTest.format('%.5w', this.date), textFormatTest.text));
+ assertEquals(this.dateString, (textFormatTest.format('%30s',
this.date), textFormatTest.text));
+ assertEquals(this.dateString, (textFormatTest.format('%30w',
this.date), textFormatTest.text));
+ assertEquals('
'+this.dateString.substring(0, 5), (textFormatTest.format('%30.5s', this.date),
textFormatTest.text));
+// assertEquals('
'+this.dateString.substring(0, 5), (textFormatTest.format('%30.5w', this.date),
textFormatTest.text));
+ assertEquals(this.dateString, (textFormatTest.format('%-s',
this.date), textFormatTest.text));
+ assertEquals(this.dateString, (textFormatTest.format('%-w',
this.date), textFormatTest.text));
+ assertEquals(this.dateString.substring(0, 5),
(textFormatTest.format('%-.5s', this.date), textFormatTest.text));
+// assertEquals(this.dateString.substring(0, 5),
(textFormatTest.format('%-.5w', this.date), textFormatTest.text));
+ assertEquals(this.dateString, (textFormatTest.format('%-30s',
this.date), textFormatTest.text));
+ assertEquals(this.dateString, (textFormatTest.format('%-30w',
this.date), textFormatTest.text));
+ assertEquals(this.dateString.substring(0, 5)+'
', (textFormatTest.format('%-30.5s', this.date), textFormatTest.text));
+// assertEquals(this.dateString.substring(0, 5)+'
', (textFormatTest.format('%-30.5w', this.date),
textFormatTest.text));
+ assertEquals('3.141592653589', (textFormatTest.format('%.14s',
Math.PI), textFormatTest.text));
+// assertEquals('3.141592653589', (textFormatTest.format('%.14w',
Math.PI), textFormatTest.text));
+ assertEquals('3.141', (textFormatTest.format('%.5s', Math.PI),
textFormatTest.text));
+// assertEquals('3.141', (textFormatTest.format('%.5w', Math.PI),
textFormatTest.text));
+ assertEquals(' 3.141592653589',
(textFormatTest.format('%30.14s', Math.PI), textFormatTest.text));
+// assertEquals(' 3.141592653589',
(textFormatTest.format('%30.14w', Math.PI), textFormatTest.text));
+ assertEquals(' 3.141',
(textFormatTest.format('%30.5s', Math.PI), textFormatTest.text));
+// assertEquals(' 3.141',
(textFormatTest.format('%30.5w', Math.PI), textFormatTest.text));
+ assertEquals('3.141592653589', (textFormatTest.format('%-.14s',
Math.PI), textFormatTest.text));
+// assertEquals('3.141592653589', (textFormatTest.format('%-.14w',
Math.PI), textFormatTest.text));
+ assertEquals('3.141', (textFormatTest.format('%-.5s', Math.PI),
textFormatTest.text));
+// assertEquals('3.141', (textFormatTest.format('%-.5w', Math.PI),
textFormatTest.text));
+ assertEquals('3.141592653589 ',
(textFormatTest.format('%-30.14s', Math.PI), textFormatTest.text));
+// assertEquals('3.141592653589 ',
(textFormatTest.format('%-30.14w', Math.PI), textFormatTest.text));
+ assertEquals('3.141 ',
(textFormatTest.format('%-30.5s', Math.PI), textFormatTest.text));
+// assertEquals('3.141 ',
(textFormatTest.format('%-30.5w', Math.PI), textFormatTest.text));
+ // 'write' compatibility mode tests
+ assertEquals('%\n', (textFormatTest.format('%'),
textFormatTest.text));
+ Debug.info("Expect an excess arguments warning");
+ assertEquals('% %\n', (textFormatTest.format('%', '%'),
textFormatTest.text));
+ assertEquals('1 2 3\n', (textFormatTest.format(1, 2, 3),
textFormatTest.text));
+ Debug.info("Expect an excess arguments warning");
+ assertEquals('%1 %2 %3\n', (textFormatTest.format('%1', '%2',
'%3'), textFormatTest.text));
+ Debug.info("Expect an excess arguments warning");
+ assertEquals('1% 2% 3%\n', (textFormatTest.format('1%', '2%',
'3%'), textFormatTest.text));
+ ]]>
+ </method>
</class>
</library>
_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins