1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-26 15:23:15 +00:00
TiddlyWiki5/editions/test/tiddlers/tests/test-utils.js
Jermolene d31f61255e A failing test for a bug with text reference parsing
I’ll fix this later.

Raised by @danielo515
2014-11-21 17:05:20 +00:00

54 lines
1.3 KiB
JavaScript

/*\
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() {
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' }
);
expect(ptr("title##index!!field")).toEqual(
{ title : 'title', index : 'index!!field' }
);
expect(ptr("title!!field##index")).toEqual(
{ title : 'title', field : 'field##index' }
);
});
});
})();