2014-05-06 17:10:27 +00:00
|
|
|
/*\
|
|
|
|
title: test-utils.js
|
|
|
|
type: application/javascript
|
|
|
|
tags: [[$:/tags/test-spec]]
|
|
|
|
|
|
|
|
Tests various utility functions.
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
describe("Utility tests", function() {
|
|
|
|
|
|
|
|
it("should handle parsing a string array", function() {
|
2014-11-21 17:05:20 +00:00
|
|
|
var psa = $tw.utils.parseStringArray;
|
|
|
|
expect(psa("Tiddler8")).toEqual(["Tiddler8"]);
|
|
|
|
expect(psa(" Tiddler8")).toEqual(["Tiddler8"]);
|
|
|
|
expect(psa("Tiddler8 ")).toEqual(["Tiddler8"]);
|
|
|
|
expect(psa("Tiddler8 two")).toEqual(["Tiddler8","two"]);
|
|
|
|
expect(psa(" Tiddler8 two ")).toEqual(["Tiddler8","two"]);
|
|
|
|
expect(psa(" Tidd\u00a0ler8 two ")).toEqual(["Tidd\u00a0ler8","two"]);
|
|
|
|
expect(psa(" [[Tidd\u00a0ler8]] two ")).toEqual(["Tidd\u00a0ler8","two"]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should parse text references", function() {
|
|
|
|
var ptr = $tw.utils.parseTextReference;
|
|
|
|
expect(ptr("title")).toEqual(
|
|
|
|
{ title : 'title' }
|
|
|
|
);
|
|
|
|
expect(ptr("ti#tle")).toEqual(
|
|
|
|
{ title : 'ti#tle' }
|
|
|
|
);
|
|
|
|
expect(ptr("ti!tle")).toEqual(
|
|
|
|
{ title : 'ti!tle' }
|
|
|
|
);
|
|
|
|
expect(ptr("ti#tle##index")).toEqual(
|
|
|
|
{ title : 'ti#tle', index : 'index' }
|
|
|
|
);
|
2014-11-21 18:16:22 +00:00
|
|
|
expect(ptr("ti!tle!!field")).toEqual(
|
|
|
|
{ title : 'ti!tle', field : 'field' }
|
|
|
|
);
|
2014-11-21 17:05:20 +00:00
|
|
|
expect(ptr("title##index!!field")).toEqual(
|
2014-11-21 18:16:22 +00:00
|
|
|
{ title : 'title##index', field : 'field' }
|
2014-11-21 17:05:20 +00:00
|
|
|
);
|
|
|
|
expect(ptr("title!!field##index")).toEqual(
|
|
|
|
{ title : 'title', field : 'field##index' }
|
|
|
|
);
|
|
|
|
|
2014-05-06 17:10:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})();
|