Switch Screenshotter data from JSON to YAML

Escaping TeX in JSON as query strings is a pain: you have to double all the
\\, you have to escape the & and the #, you can't easily include line breaks
for readability, and so on.  YAML solves most of these problems for most of
the situations.  Now each test case can be structured, while simple test
cases only consist of a line of verbatim TeX code, with no escaping.

The most troublesome items remaining are lines starting in { since in YAML
these would denote inline mapping types. We use block notation for these.
This commit is contained in:
Martin von Gagern
2015-07-15 16:50:47 +02:00
parent a3031af307
commit fb403fa9eb
7 changed files with 137 additions and 72 deletions

View File

@@ -8,7 +8,7 @@ var net = require("net");
var selenium = require("selenium-webdriver");
var app = require("../../server");
var data = require("../../test/screenshotter/ss_data.json");
var data = require("../../test/screenshotter/ss_data");
var dstDir = path.normalize(
path.join(__dirname, "..", "..", "test", "screenshotter", "images"));
@@ -130,8 +130,6 @@ if (seleniumURL) {
console.log("Selenium driver in local session");
}
var toStrip = "http://localhost:7936/"; // remove this from testcase URLs
process.nextTick(startServer);
var attempts = 0;
@@ -248,12 +246,12 @@ function takeScreenshots() {
}
function takeScreenshot(key) {
var url = data[key];
if (!url) {
var itm = data[key];
if (!itm) {
console.error("Test case " + key + " not known!");
return;
}
url = katexURL + url.substr(toStrip.length);
var url = katexURL + "test/screenshotter/test.html?" + itm.query;
driver.get(url);
driver.takeScreenshot().then(function haveScreenshot(img) {
img = imageDimensions(img);

View File

@@ -1,6 +1,5 @@
"use strict";
var querystring = require("querystring");
var childProcess = require("child_process");
var fs = require("fs");
var path = require("path");
@@ -16,18 +15,12 @@ var readFile = Q.denodeify(fs.readFile);
var writeFile = Q.denodeify(fs.writeFile);
var mkdir = Q.denodeify(fs.mkdir);
// ignore some tests, since they contain commands not supported by LaTeX
var blacklist = {
Colors: "Color handling differs",
DeepFontSizing: "\\Huge inside \\dfrac doesn't work for some reason",
KaTeX: "Custom command, doesn't exist in LaTeX"
};
var todo;
if (process.argv.length > 2) {
todo = process.argv.slice(2);
} else {
todo = Object.keys(data).filter(function(key) {
return !blacklist[key];
return !data[key].nolatex;
});
}
@@ -63,22 +56,16 @@ Q.all([
// Process a single test case: rasterize, then create diff
function processTestCase(key) {
if (blacklist[key]) {
return;
var itm = data[key];
var tex = "$" + itm.tex + "$";
if (itm.display) {
tex = "\\[" + itm.tex + "\\]";
}
var url = data[key];
var query = url.replace(/^.*?\?/, ""); // extract query string
query = query.replace(/\+/g, "%2B"); // plus doesn't mean space here
query = querystring.parse(query);
var tex = "$" + query.m + "$";
if (query.display) {
tex = "$$" + query.m + "$$";
if (itm.pre) {
tex = itm.pre.replace("<br>", "\\\\") + tex;
}
if (query.pre) {
tex = query.pre.replace("<br>", "\\\\") + tex;
}
if (query.post) {
tex = tex + query.post.replace("<br>", "\\\\");
if (itm.post) {
tex = tex + itm.post.replace("<br>", "\\\\");
}
tex = template.replace(/\$.*\$/, tex.replace(/\$/g, "$$$$"));
var texFile = path.join(tmpDir, key + ".tex");