Merge pull request #574 from danvk/test-warnings
[dygraphs.git] / auto_tests / tests / parser.js
... / ...
CommitLineData
1/**
2 * @fileoverview Tests the way that dygraphs parses data.
3 *
4 * @author danvk@google.com (Dan Vanderkam)
5 */
6describe("parser", function() {
7
8beforeEach(function() {
9 document.body.innerHTML = "<div id='graph'></div>";
10});
11
12afterEach(function() {
13});
14
15it('testDetectLineDelimiter', function() {
16 var data = "X,Y\r" +
17 "0,-1\r" +
18 "1,0\r" +
19 "2,1\r" +
20 "3,0\r"
21 ;
22 assert.equal("\r", Dygraph.detectLineDelimiter(data));
23
24 data = "X,Y\n" +
25 "0,-1\n" +
26 "1,0\n" +
27 "2,1\n" +
28 "3,0\n"
29 ;
30 assert.equal("\n", Dygraph.detectLineDelimiter(data));
31
32 data = "X,Y\n\r" +
33 "0,-1\n\r" +
34 "1,0\n\r" +
35 "2,1\n\r" +
36 "3,0\n\r"
37 ;
38 assert.equal("\n\r", Dygraph.detectLineDelimiter(data));
39});
40
41it('testParseDosNewlines', function() {
42 var opts = {
43 width: 480,
44 height: 320
45 };
46 var data = "X,Y\r" +
47 "0,-1\r" +
48 "1,0\r" +
49 "2,1\r" +
50 "3,0\r"
51 ;
52
53 var g = new Dygraph('graph', data, opts);
54 assert.equal(0, g.getValue(0, 0));
55 assert.equal(-1, g.getValue(0, 1));
56 assert.equal(1, g.getValue(1, 0));
57 assert.equal(0, g.getValue(1, 1));
58 assert.deepEqual(['X', 'Y'], g.getLabels());
59});
60
61it('should parse tab-delimited data', function() {
62 var data = "X\tY\n" +
63 "0\t-1\n" +
64 "1\t0\n" +
65 "2\t1\n" +
66 "3\t0\n";
67
68 var g = new Dygraph('graph', data);
69 assert.equal(0, g.getValue(0, 0));
70 assert.equal(-1, g.getValue(0, 1));
71 assert.equal(1, g.getValue(1, 0));
72 assert.equal(0, g.getValue(1, 1));
73 assert.deepEqual(['X', 'Y'], g.getLabels());
74});
75
76it('should parse fractions', function() {
77 var data = "X,Y\n" +
78 "0,1/4\n" +
79 "1,2/4\n" +
80 "2,3/4\n" +
81 "3,4/4\n";
82 var g = new Dygraph('graph', data, {fractions:true});
83
84 assert.equal(0, g.getValue(0, 0));
85 assert.deepEqual([1, 4], g.getValue(0, 1));
86 assert.equal(1, g.getValue(1, 0));
87 assert.deepEqual([2, 4], g.getValue(1, 1));
88 assert.deepEqual(['X', 'Y'], g.getLabels());
89});
90
91it('should parse error bars', function() {
92 var data = "X,Y\n" +
93 "0,1,4\n" +
94 "1,2,4\n" +
95 "2,3,4\n" +
96 "3,4,4\n";
97 var g = new Dygraph('graph', data, {errorBars:true});
98
99 assert.equal(0, g.getValue(0, 0));
100 assert.deepEqual([1, 4], g.getValue(0, 1));
101 assert.equal(1, g.getValue(1, 0));
102 assert.deepEqual([2, 4], g.getValue(1, 1));
103 assert.deepEqual(['X', 'Y'], g.getLabels());
104});
105
106it('should parse custom bars', function() {
107 var data = "X,Y1,Y2\n" +
108 "1,10;20;30,20;5;25\n" +
109 "2,10;25;35,20;10;25\n";
110 var g = new Dygraph('graph', data, {customBars:true});
111
112 assert.equal(1, g.getValue(0, 0));
113 assert.deepEqual([10, 20, 30], g.getValue(0, 1));
114 assert.deepEqual([20, 5, 25], g.getValue(0, 2));
115 assert.equal(2, g.getValue(1, 0));
116 assert.deepEqual([10, 25, 35], g.getValue(1, 1));
117 assert.deepEqual([20, 10, 25], g.getValue(1, 2));
118 assert.deepEqual(['X', 'Y1', 'Y2'], g.getLabels());
119});
120
121/*
122it('should warn on unsorted input', function() {
123});
124
125it('should warn on different length columns', function() {
126});
127
128it('should detect double-labeled data', function() {
129});
130*/
131
132});