Eliminate and repair Javascript breaks

I am writing a markdown compiler in Erlang for server-side use. Since I will need to work with clients, I decided to use the client side library (showdown.js) as a specification, and then check my code for compatibility with this.

In the first two iterations, I created 260-bit unit tests that checked that my program produced output that was compatible with what I considered a valid markdown based on reading the syntax note .

But now I'm trying to write a javascript program to create unit tests.

I have an input like:

"3 > 4\na"

I want to run an autopsy on it to get:

"<p>3 &gt; 4\na</p>"

and I want to stitch this into EUnit statement:

"?_assert(conv(\"3 > 4\na\") == \"<p>3 &gt; 4\na</p>\"),",

Erlang unit test. unit test, -, , javascript, , <textarea /> EUnit.

, \n , :

"?_assert(conv(\"3 > 4
a\") == \"<p>3 &gt; 4
a</p>\"),",

, :

text.replace("\\", "\\\\");
text.replace("\n", "\\n");

...

+3
1
, - -, , : (

:

var converter;
var text = "";
var item;
var input;
var output;
var head;
var tail;
converter = new Attacklab.showdown.converter();
item = document.getElementById("tests");
for (var test in tests) {
  input = tests[test].replace(/[\n\r]+/gi,"\\n" );
  input = input.replace(/[\"]+/gi, "\\\"");
  output = converter.makeHtml(tests[test]).replace(/[\n\r]+/gi, "\\n");
  output = output.replace(/[\"]+/gi, "\\\"");
  text += "     ?_assert(conv(\"" + input + "\") == \"" + output + "\"),\n";
};
head = "unit_test_() -> \n    [\n";
tail = "\n    ].";
text = text.slice(0, text.length - 2);
item.value = head + text + tail;
+2

Source: https://habr.com/ru/post/1719229/


All Articles