summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ddl_builder/qunit/columnTypes.js17
-rw-r--r--ddl_builder/qunit/fixture.html145
-rw-r--r--ddl_builder/qunit/guessValueSeparators.js31
-rw-r--r--ddl_builder/qunit/headerNames.js22
-rw-r--r--ddl_builder/qunit/main.js33
-rw-r--r--ddl_builder/qunit/recordCount.js19
-rw-r--r--qunit_main.js2
7 files changed, 123 insertions, 146 deletions
diff --git a/ddl_builder/qunit/columnTypes.js b/ddl_builder/qunit/columnTypes.js
index a182e7d..aed8de0 100644
--- a/ddl_builder/qunit/columnTypes.js
+++ b/ddl_builder/qunit/columnTypes.js
@@ -1,17 +1,8 @@
-require(["jQuery","QUnit", "DDLBuilder/ddl_builder"], function ($,test,DDLBuilder) {
+define(["jQuery","QUnit", "DDLBuilder/ddl_builder"], function ($,QUnit,DDLBuilder) {
- test("ddl_builder.columnTypes", function () {
- var typeTest = function (id,types) {
+ return function (id,types) {
var ddl_builder = new DDLBuilder({ddlTemplate: "{{#each_with_index columns}}{{#if index}},{{/if}}{{db_type}}{{/each_with_index}}}"});
- equal(ddl_builder.parse($("#" + id).html()), types);
- }
- typeTest("simplestFormattedCSV","int,int");
- typeTest("twoColumnFixedWidth","int,varchar(5)");
- typeTest("fixedWidthDates","datetime,datetime,int,int,varchar(7)");
- typeTest("centeredPipes","varchar(1),int");
- typeTest("ASCII_bordered","int,int,datetime,int");
- typeTest("fixedWidthWithSpaces","varchar(6),varchar(13)");
- typeTest("pipedColumns","varchar(8),int,numeric");
- });
+ QUnit.equal(ddl_builder.parse($("#" + id).html()), types);
+ };
});
diff --git a/ddl_builder/qunit/fixture.html b/ddl_builder/qunit/fixture.html
index a53c5c1..4cd140c 100644
--- a/ddl_builder/qunit/fixture.html
+++ b/ddl_builder/qunit/fixture.html
@@ -1,72 +1,73 @@
-
-<span id="simplestFormattedCSV">
- a,b
- 1,2
-</span>
-<span id="twoColumnFixedWidth">
- Period Result
- 1 Green
- 1 Blue
- 1 Blue
- 1 Red
- 1 Blue
- 1 Blue
- 1 Blue
- 2 Green
- 2 Green
- 2 Green
- 2 Blue
- 2 Red
- 2 Red
-</span>
-<span id="fixedWidthDates">
- date_due date_paid amount_due amount_paid category_type
- 2012-08-12 2012-08-12 500 450 Income
- 2012-08-13 2012-08-17 200 300 Expense
- 2012-09-15 2012-09-13 300 300 Income
- 2012-09-17 2012-09-16 100 100 Income
-</span>
-<span id="centeredPipes">
- L | N
- -------------------
- A | 1
- A | 3
- A | 5
- B | 5
- B | 7
- B | 9
- C | 1
- C | 2
- C | 3
-</span>
-<span id="ASCII_bordered">
- +-----------+--------------+----------+--------+
- | IdPayment | Costs_IdCost | Date | Amount |
- +-----------+--------------+----------+--------+
- | 1 | 2 |2012/09/10| 1000 |
- +-----------+--------------+----------+--------+
- | 2 | 2 |2012/09/20| 3000 |
- +-----------+--------------+----------+--------+
- | 3 | 2 |2012/10/01| 5000 |
- +-----------+--------------+----------+--------+
-</span>
-<span id="fixedWidthWithSpaces">
- Cul 1 Cul 2
- =====================
- A10000 Test
- A10001 Test 123
- A20000 Test 1
- A20001 Test 999
- A30000 Test 2
- A30002 Test 5555
- A40000 Test 3
- A40006 Test 84384848
-</span>
-<span id="pipedColumns">
- Scoreband| TotalNoOfPeople | AvgScore
- --------------------------------
- -5 to 0 | 2 | -2
- 0 to 5 | 3 | 2
- 5 to 10 | 2 | 8
- 10 to 15 | 3 | 13.3
-</span>
+<div id="ddlInputText">
+ <span id="simplestFormattedCSV" types="int,int" valueSeparator="," headers="a,b" recordCount="1">
+ a,b
+ 1,2
+ </span>
+ <span id="twoColumnFixedWidth" types="int,varchar(5)" valueSeparator="/\s\s+/" headers="Period,Result" recordCount="13">
+ Period Result
+ 1 Green
+ 1 Blue
+ 1 Blue
+ 1 Red
+ 1 Blue
+ 1 Blue
+ 1 Blue
+ 2 Green
+ 2 Green
+ 2 Green
+ 2 Blue
+ 2 Red
+ 2 Red
+ </span>
+ <span id="fixedWidthDates" types="datetime,datetime,int,int,varchar(7)" valueSeparator="/\s\s+/" headers="date_due,date_paid,amount_due,amount_paid,category_type" recordCount="4">
+ date_due date_paid amount_due amount_paid category_type
+ 2012-08-12 2012-08-12 500 450 Income
+ 2012-08-13 2012-08-17 200 300 Expense
+ 2012-09-15 2012-09-13 300 300 Income
+ 2012-09-17 2012-09-16 100 100 Income
+ </span>
+ <span id="centeredPipes" types="varchar(1),int" valueSeparator="|" headers="L,N" recordCount="9">
+ L | N
+ -------------------
+ A | 1
+ A | 3
+ A | 5
+ B | 5
+ B | 7
+ B | 9
+ C | 1
+ C | 2
+ C | 3
+ </span>
+ <span id="ASCII_bordered" types="int,int,datetime,int" valueSeparator="|" headers="IdPayment,Costs_IdCost,Date,Amount" recordCount="3">
+ +-----------+--------------+----------+--------+
+ | IdPayment | Costs_IdCost | Date | Amount |
+ +-----------+--------------+----------+--------+
+ | 1 | 2 |2012/09/10| 1000 |
+ +-----------+--------------+----------+--------+
+ | 2 | 2 |2012/09/20| 3000 |
+ +-----------+--------------+----------+--------+
+ | 3 | 2 |2012/10/01| 5000 |
+ +-----------+--------------+----------+--------+
+ </span>
+ <span id="fixedWidthWithSpaces" types="varchar(6),varchar(13)" valueSeparator="/\s\s+/" headers="Cul 1,Cul 2" recordCount="8">
+ Cul 1 Cul 2
+ =====================
+ A10000 Test
+ A10001 Test 123
+ A20000 Test 1
+ A20001 Test 999
+ A30000 Test 2
+ A30002 Test 5555
+ A40000 Test 3
+ A40006 Test 84384848
+ </span>
+ <span id="pipedColumns" types="varchar(8),int,numeric" valueSeparator="|" headers="Scoreband,TotalNoOfPeople,AvgScore" recordCount="4">
+ Scoreband| TotalNoOfPeople | AvgScore
+ --------------------------------
+ -5 to 0 | 2 | -2
+ 0 to 5 | 3 | 2
+ 5 to 10 | 2 | 8
+ 10 to 15 | 3 | 13.3
+ </span>
+</div>
diff --git a/ddl_builder/qunit/guessValueSeparators.js b/ddl_builder/qunit/guessValueSeparators.js
index f58aa0c..6aff1ae 100644
--- a/ddl_builder/qunit/guessValueSeparators.js
+++ b/ddl_builder/qunit/guessValueSeparators.js
@@ -1,22 +1,15 @@
-require(["jQuery","QUnit", "DDLBuilder/ddl_builder"], function ($,test,DDLBuilder) {
+define(["jQuery","QUnit", "DDLBuilder/ddl_builder"], function ($,QUnit,DDLBuilder) {
- test("ddl_builder.guessValueSeparators", function () {
- var ddl_builder = new DDLBuilder();
-
- var sepTest = function(id,sep) {
- var result = ddl_builder.guessValueSeparator($("#" + id).html());
- if (result.separator)
- equal(ddl_builder.guessValueSeparator($("#" + id).html()).separator.toString(), sep.toString());
- else
- ok(false, "Guess failed with message:" + result.message);
- }
- sepTest("simplestFormattedCSV",",");
- sepTest("twoColumnFixedWidth",/\s\s+/);
- sepTest("fixedWidthDates",/\s\s+/);
- sepTest("centeredPipes","|");
- sepTest("ASCII_bordered","|");
- sepTest("fixedWidthWithSpaces",/\s\s+/);
- sepTest("pipedColumns","|");
- });
+ return function(id,sep) {
+
+ var ddl_builder = new DDLBuilder(),
+ result = ddl_builder.guessValueSeparator($("#" + id).html());
+
+ if (result.separator)
+ QUnit.equal(ddl_builder.guessValueSeparator($("#" + id).html()).separator.toString(), sep.toString());
+ else
+ QUnit.ok(false, "Guess failed with message:" + result.message);
+ };
+
});
diff --git a/ddl_builder/qunit/headerNames.js b/ddl_builder/qunit/headerNames.js
index 8d71227..2a6da45 100644
--- a/ddl_builder/qunit/headerNames.js
+++ b/ddl_builder/qunit/headerNames.js
@@ -1,18 +1,8 @@
-require(["jQuery","QUnit", "DDLBuilder/ddl_builder"], function ($,test,DDLBuilder) {
-
- test("ddl_builder.headerNames", function () {
- // template is just a csv list of names
- var headTest = function (id,headers) {
- var ddl_builder = new DDLBuilder({ddlTemplate: "{{#each_with_index columns}}{{#if index}},{{/if}}{{name}}{{/each_with_index}}}"});
- equal(ddl_builder.parse($("#" + id).html()), headers);
- }
- headTest("simplestFormattedCSV", "a,b");
- headTest("twoColumnFixedWidth", "Period,Result");
- headTest("fixedWidthDates", "date_due,date_paid,amount_due,amount_paid,category_type");
- headTest("centeredPipes", "L,N");
- headTest("ASCII_bordered", "IdPayment,Costs_IdCost,Date,Amount");
- headTest("fixedWidthWithSpaces", "Cul 1,Cul 2");
- headTest("pipedColumns", "Scoreband,TotalNoOfPeople,AvgScore");
- });
+define(["jQuery","QUnit", "DDLBuilder/ddl_builder"], function ($,QUnit,DDLBuilder) {
+ return function (id,headers) {
+ var ddl_builder = new DDLBuilder({ddlTemplate: "{{#each_with_index columns}}{{#if index}},{{/if}}{{name}}{{/each_with_index}}}"});
+ QUnit.equal(ddl_builder.parse($("#" + id).html()), headers);
+ };
+
});
diff --git a/ddl_builder/qunit/main.js b/ddl_builder/qunit/main.js
index 29ef77f..ad023ad 100644
--- a/ddl_builder/qunit/main.js
+++ b/ddl_builder/qunit/main.js
@@ -1,18 +1,29 @@
define([
"jQuery",
- "text!./fixture.html"
+ "QUnit",
+ "text!./fixture.html",
+ "./columnTypes",
+ "./guessValueSeparators",
+ "./headerNames",
+ "./recordCount"
],
- function ($,fixtureContent) {
-
+ function ($,QUnit,fixtureContent,
+ columnTypes,guessValueSeparators,
+ headerNames,recordCount) {
+
$("#qunit-fixture").append(fixtureContent);
-
- require([
- "DDLBuilder/qunit/columnTypes",
- "DDLBuilder/qunit/headerNames",
- "DDLBuilder/qunit/guessValueSeparators",
- "DDLBuilder/qunit/recordCount"
- ]);
-
+
+ $("#qunit-fixture #ddlInputText span").each(function () {
+ var $this = $(this);
+ QUnit.test("Parsing " + this.id, function () {
+ columnTypes($this.attr('id'), $this.attr('types'));
+ guessValueSeparators($this.attr('id'), $this.attr('valueSeparator'));
+ headerNames($this.attr('id'), $this.attr('headers'));
+ recordCount($this.attr('id'), $this.attr('recordCount'));
+
+ });
+ });
+
}
) \ No newline at end of file
diff --git a/ddl_builder/qunit/recordCount.js b/ddl_builder/qunit/recordCount.js
index bcb71c5..660f27d 100644
--- a/ddl_builder/qunit/recordCount.js
+++ b/ddl_builder/qunit/recordCount.js
@@ -1,21 +1,12 @@
-require(["jQuery","QUnit", "DDLBuilder/ddl_builder"], function ($,test,DDLBuilder) {
+define(["jQuery","QUnit", "DDLBuilder/ddl_builder"], function ($,QUnit,DDLBuilder) {
- test("ddl_builder.recordCount", function () {
- var countTest = function (id,count) {
+ return function (id,count) {
var ddl_builder = new DDLBuilder({ddlTemplate: "[{{#each_with_index data}}{{#if index}},{{/if}}}{{index}}{{/each_with_index}}}]"});
var result = ddl_builder.parse($("#" + id).html());
if ($.parseJSON(result))
- equal($.parseJSON(result).length, count);
+ QUnit.equal($.parseJSON(result).length, count);
else
- ok(false, "Unable to parse result to JSON array ("+ result +")");
- }
- countTest("simplestFormattedCSV",1);
- countTest("twoColumnFixedWidth",13);
- countTest("fixedWidthDates",4);
- countTest("centeredPipes",9);
- countTest("ASCII_bordered",3);
- countTest("fixedWidthWithSpaces",8);
- countTest("pipedColumns",4);
- });
+ QUnit.ok(false, "Unable to parse result to JSON array ("+ result +")");
+ };
});
diff --git a/qunit_main.js b/qunit_main.js
index fdcf6fa..f9c0a52 100644
--- a/qunit_main.js
+++ b/qunit_main.js
@@ -20,7 +20,7 @@ requirejs.config({
exports: 'dateFormat'
},
QUnit: {
- exports: "test"
+ exports: function () { return { "test": test, "equal": equal, "ok": ok } }
}
}