summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjakefeasel <jfeasel@gmail.com>2012-09-30 23:00:24 -0700
committerjakefeasel <jfeasel@gmail.com>2012-09-30 23:00:24 -0700
commit81b96200a1c21d6e5a94ad1ee7d11eccf07bba40 (patch)
tree292a84b1edcf4f750513e0d51247c78665dc5bcf
parent4cdadc12015ed1e6461d2320f12aaa6f63edc76b (diff)
downloadsqlfiddle-81b96200a1c21d6e5a94ad1ee7d11eccf07bba40.zip
sqlfiddle-81b96200a1c21d6e5a94ad1ee7d11eccf07bba40.tar.gz
sqlfiddle-81b96200a1c21d6e5a94ad1ee7d11eccf07bba40.tar.bz2
Bringing in updates from main project
-rw-r--r--javascripts/libs/ddl_builder/ddl_builder.js107
-rw-r--r--javascripts/libs/ddl_builder/qunit/columnTypes.js17
-rw-r--r--javascripts/libs/ddl_builder/qunit/fixture.html152
-rw-r--r--javascripts/libs/ddl_builder/qunit/guessValueSeparators.js31
-rw-r--r--javascripts/libs/ddl_builder/qunit/headerNames.js22
-rw-r--r--javascripts/libs/ddl_builder/qunit/main.js32
-rw-r--r--javascripts/libs/ddl_builder/qunit/recordCount.js19
7 files changed, 187 insertions, 193 deletions
diff --git a/javascripts/libs/ddl_builder/ddl_builder.js b/javascripts/libs/ddl_builder/ddl_builder.js
index 7db9105..67f541b 100644
--- a/javascripts/libs/ddl_builder/ddl_builder.js
+++ b/javascripts/libs/ddl_builder/ddl_builder.js
@@ -228,7 +228,12 @@ define(
}
else if (lines[i].search(/[A-Z0-9_]/i) != -1)
{
- if ($.trim(lines[i]).split(found_separator).length != column_count)
+ if ($.trim(lines[i]).split(found_separator).length != column_count &&
+ (
+ found_separator.toString() != /\s\s+/.toString() ||
+ $.trim(lines[i]).split(/\s+/).length != column_count
+ )
+ )
return {status: false, message: 'Line ' + i + ' does not have the same number of columns as the header, based on separator "' + found_separator + '".'};
}
@@ -257,63 +262,69 @@ define(
for (var i=0;i<lines.length;i++)
{
- if ($.trim(lines[i]).length && $.trim(lines[i]).split(this.valueSeparator).length == this.column_count)
- {
-
- var elements = $.trim(lines[i]).split(this.valueSeparator);
-
+ var elements = $.trim(lines[i]).split(this.valueSeparator);
- if (! this.definition.columns.length)
+ if ($.trim(lines[i]).length &&
+ (
+ elements.length == this.column_count ||
+ (
+ this.valueSeparator.toString() == /\s\s+/.toString() &&
+ (elements = $.trim(lines[i]).split(/\s+/)).length == this.column_count
+ )
+ )
+ )
+ {
+ if (! this.definition.columns.length)
+ {
+ for (var j = 0; j < elements.length; j++)
{
- for (var j = 0; j < elements.length; j++)
- {
- var value = $.trim(elements[j]);
- if (value.length)
- this.definition.columns.push({"name": value});
- else
- this.definition.columns.push(false);
- }
+ var value = $.trim(elements[j]);
+ if (value.length)
+ this.definition.columns.push({"name": value});
+ else
+ this.definition.columns.push(false);
}
- else
+ }
+ else
+ {
+
+ var tmpRow = [];
+ for (var j = 0; j < elements.length; j++)
{
-
- var tmpRow = [];
- for (var j = 0; j < elements.length; j++)
+ if (this.definition.columns[j] !== false)
{
- if (this.definition.columns[j] !== false)
+ var value = $.trim(elements[j]).replace(/'/g, "''");
+
+ // if the current field is not a number, or if we have previously decided that this one of the non-numeric field types...
+ if (isNaN(value) || this.definition.columns[j].type == 'dateType' || this.definition.columns[j].type == 'charType')
{
- var value = $.trim(elements[j]).replace(/'/g, "''");
-
- // if the current field is not a number, or if we have previously decided that this one of the non-numeric field types...
- if (isNaN(value) || this.definition.columns[j].type == 'dateType' || this.definition.columns[j].type == 'charType')
- {
-
- // if we haven't previously decided that this is a character field, and it can be cast as a date, then declare it a date
- if (this.definition.columns[j].type != 'charType' && !isNaN(Date.parse(value)) )
- this.definition.columns[j].type = "dateType";
- else
- this.definition.columns[j].type = "charType";
- }
- else // this must be some kind of number field
- {
- if (this.definition.columns[j].type != 'floatType' && value % 1 != 0)
- this.definition.columns[j].type = 'floatType';
- else
- this.definition.columns[j].type = 'intType';
- }
-
- if (!this.definition.columns[j].length || value.length > this.definition.columns[j].length)
- {
- this.definition.columns[j].length = value.length;
- }
- tmpRow.push({v:value});
+ // if we haven't previously decided that this is a character field, and it can be cast as a date, then declare it a date
+ if (this.definition.columns[j].type != 'charType' && !isNaN(Date.parse(value)) )
+ this.definition.columns[j].type = "dateType";
+ else
+ this.definition.columns[j].type = "charType";
}
-
+ else // this must be some kind of number field
+ {
+ if (this.definition.columns[j].type != 'floatType' && value % 1 != 0)
+ this.definition.columns[j].type = 'floatType';
+ else
+ this.definition.columns[j].type = 'intType';
+ }
+
+ if (!this.definition.columns[j].length || value.length > this.definition.columns[j].length)
+ {
+ this.definition.columns[j].length = value.length;
+ }
+
+ tmpRow.push({v:value});
}
- this.definition.data.push({r: tmpRow});
-
+
}
+ this.definition.data.push({r: tmpRow});
+
+ }
}
}
diff --git a/javascripts/libs/ddl_builder/qunit/columnTypes.js b/javascripts/libs/ddl_builder/qunit/columnTypes.js
index a182e7d..6ad3301 100644
--- a/javascripts/libs/ddl_builder/qunit/columnTypes.js
+++ b/javascripts/libs/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, "Column types");
+ };
});
diff --git a/javascripts/libs/ddl_builder/qunit/fixture.html b/javascripts/libs/ddl_builder/qunit/fixture.html
index a53c5c1..a152620 100644
--- a/javascripts/libs/ddl_builder/qunit/fixture.html
+++ b/javascripts/libs/ddl_builder/qunit/fixture.html
@@ -1,72 +1,80 @@
-
-<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>
+ <span id="variableSpaceDelimited" types="varchar(3),varchar(4),varchar(5)" valueSeparator="/\s\s+/" headers="c1,c2,c3" recordCount="4">
+ c1 c2 c3
+ 1A2 cat black
+ 1G2 dog red
+ B11 frog green
+ 1G2 girl red
+ </span>
+</div>
diff --git a/javascripts/libs/ddl_builder/qunit/guessValueSeparators.js b/javascripts/libs/ddl_builder/qunit/guessValueSeparators.js
index f58aa0c..59a4f50 100644
--- a/javascripts/libs/ddl_builder/qunit/guessValueSeparators.js
+++ b/javascripts/libs/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(), "Guessing Value Separators");
+ else
+ QUnit.ok(false, "Guess failed with message:" + result.message);
+ };
+
});
diff --git a/javascripts/libs/ddl_builder/qunit/headerNames.js b/javascripts/libs/ddl_builder/qunit/headerNames.js
index 8d71227..d8107ad 100644
--- a/javascripts/libs/ddl_builder/qunit/headerNames.js
+++ b/javascripts/libs/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, "Finding header names");
+ };
+
});
diff --git a/javascripts/libs/ddl_builder/qunit/main.js b/javascripts/libs/ddl_builder/qunit/main.js
index 29ef77f..8abd0a7 100644
--- a/javascripts/libs/ddl_builder/qunit/main.js
+++ b/javascripts/libs/ddl_builder/qunit/main.js
@@ -1,18 +1,28 @@
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/javascripts/libs/ddl_builder/qunit/recordCount.js b/javascripts/libs/ddl_builder/qunit/recordCount.js
index bcb71c5..90791a5 100644
--- a/javascripts/libs/ddl_builder/qunit/recordCount.js
+++ b/javascripts/libs/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, "Getting Record 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 +")");
+ };
});