1 | var markdown = require('markdown')
|
2 |
|
3 | function test_dialect( dialect, features ) {
|
4 | var dialect_test = exports[ "test_" + dialect ] = {};
|
5 |
|
6 | for ( var f in features ) {
|
7 | ( function( feature ) {
|
8 | dialect_test[ "test_" + feature ] = function() {
|
9 | var test_path = path + feature + "/";
|
10 |
|
11 |
|
12 | var tests = fs.list( test_path );
|
13 |
|
14 |
|
15 | tests = tests.filter( function( x ) {return x.match( /\.text$/ ) } );
|
16 |
|
17 |
|
18 | tests = tests.map( function( x ) {return x.replace( /\.text$/, "" ) } );
|
19 |
|
20 | for ( var t in tests ) {
|
21 |
|
22 | var test_name = tests[ t ].substring( tests[ t ].lastIndexOf( "/" ) + 1 ),
|
23 | text = slurpFile( test_path + tests[ t ] + ".text" );
|
24 |
|
25 |
|
26 | if ( fs.isFile( test_path + tests[ t ] + ".json" ) ) {
|
27 | try {
|
28 | var json_text = slurpFile( test_path + tests[ t ] + ".json" );
|
29 | var json = JSON.parse( json_text );
|
30 |
|
31 | var output = markdown.toHTMLTree( text, dialect );
|
32 | asserts.same( output, json, test_name );
|
33 | }
|
34 | catch( e ) {
|
35 | asserts.ok( 0, "Failed with error on " + test_name + ": " + e );
|
36 | if ( e.stack )
|
37 | asserts.diag( e.stack );
|
38 | }
|
39 | }
|
40 | else {
|
41 | asserts.ok( 0, "No target output for " + test_name );
|
42 | }
|
43 | }
|
44 | }
|
45 | } )( features[ f ] );
|
46 | }
|
47 | }
|
48 |
|
49 |
|
50 |
|
51 | if ( typeof process != "undefined" && process.title == "node" ) {
|
52 |
|
53 | var test = require( 'patr/runner' ),
|
54 | asserts = require( 'assert' ),
|
55 | n_fs = require( 'fs' ),
|
56 | args = process.argv.splice( 1 ),
|
57 | path = __dirname + "/features/";
|
58 |
|
59 | test.runner = test.run;
|
60 |
|
61 | var slurpFile = function( f ) {
|
62 | return n_fs.readFileSync( f, 'utf8' );
|
63 | }
|
64 |
|
65 | var fs = {
|
66 | list: n_fs.readdirSync,
|
67 | rawOpen: n_fs.openSync,
|
68 | isFile: function( f ) {
|
69 | return n_fs.statSync( f ).isFile()
|
70 | },
|
71 | };
|
72 |
|
73 | asserts.same = asserts.deepEqual;
|
74 | }
|
75 | else {
|
76 |
|
77 | var test = require('test');
|
78 | asserts = test.asserts,
|
79 | fs = require( "fs-base" ),
|
80 | args = require( "system" ).args.splice( 1 ),
|
81 | path = module.resource.resolve( "features" );
|
82 |
|
83 | var slurpFile = function ( f ) {
|
84 | var s = fs.rawOpen( f, "r" );
|
85 | var t = s.readWhole();
|
86 | s.close();
|
87 | return t;
|
88 | }
|
89 | }
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | if ( require.main === module ) {
|
95 | var dialects = {};
|
96 | dialects.Gruber = [
|
97 | "blockquotes",
|
98 | "code",
|
99 | "emphasis",
|
100 | "headers",
|
101 | "horizontal_rules",
|
102 | "images",
|
103 | "linebreaks",
|
104 | "links",
|
105 | "lists"
|
106 | ];
|
107 |
|
108 | dialects.Maruku = dialects.Gruber.slice( 0 );
|
109 | dialects.Maruku.push( "meta", "definition_lists" );
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 | for ( d in dialects ) {
|
117 | test_dialect( d, dialects[ d ] );
|
118 | }
|
119 |
|
120 | test.runner( exports );
|
121 | }
|