From 57154831f03ec3c7d43d398c9c748935122ca344 Mon Sep 17 00:00:00 2001 From: Robert Konigsberg Date: Fri, 23 Nov 2012 15:19:25 -0500 Subject: [PATCH] Add sanity test for xValueParser. --- auto_tests/tests/formats.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/auto_tests/tests/formats.js b/auto_tests/tests/formats.js index 78e2240..38ba88e 100644 --- a/auto_tests/tests/formats.js +++ b/auto_tests/tests/formats.js @@ -58,6 +58,28 @@ FormatsTestCase.prototype.testFunctionDefinesArray = function() { this.assertData(g); }; +FormatsTestCase.prototype.testXValueParser = function() { + var data = + "X,Y\n" + + "d,-1\n" + + "e,0\n" + + "f,1\n" + + "g,0\n"; + + var graph = document.getElementById("graph"); + var g = new Dygraph(graph, data, { + xValueParser : function(str) { + assertEquals(1, str.length); + return str.charCodeAt(0) - "a".charCodeAt(0); + } + }); + + assertEquals(3, g.getValue(0, 0)); + assertEquals(4, g.getValue(1, 0)); + assertEquals(5, g.getValue(2, 0)); + assertEquals(6, g.getValue(3, 0)); +}; + FormatsTestCase.prototype.assertData = function(g) { var expected = this.dataArray; -- 2.7.4