Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Port the tests to Mocha. And some of the missed PyYAML tests. #57

merged 111 commits into from Dec 20, 2012


None yet
2 participants

dervus commented Dec 19, 2012

Ported from PyYAML:

  • Reader tests.
  • Mark tests.
  • Constructor tests.
  • "Canonical" tests. Note: I have modified them in order to remove terrible code duplication.

Marked as "unsupported":

  • IO tests. (*.unicode) They test loading of UTF-16 and UTF-32 encoded documents.
  • All of non-UTF-8 test samples.
  • Python-specific constructor test samples.

Cuted off:


  • Constructor test samples for JavaScript-specific tags.

dervus added some commits Nov 30, 2012

@dervus dervus Remove old helpers and suites. 8c9e409
@dervus dervus Add new functional test helpers.
Switch to Mocha and hide Node-specific APIs from tests, which does not
need them.
@dervus dervus Remove 'functional-' prefix from test names. 9740aac
@dervus dervus Port 'functional/errors' tests to new API. 8a85599
@dervus dervus Port 'functional/resolver' tests to new API. 166484c
@dervus dervus Port 'functional/structure' tests to new API. 52dd270
@dervus dervus Port 'functional/tokens' tests to new API. 6e99970
@dervus dervus Add test suite for functional tests. 973c9d1
@dervus dervus Add 'functional/mark' tests. 7d542d0
@dervus dervus Add JS-YAML-TEST package.
It is intended to use as a framework for the tests, and it will contain
all of the helpers, utilities, and other shared code.
@dervus dervus Move functional test helpers to JS-YAML-TEST. 740cec9
@dervus dervus Add functional/constructor tests. 2fee388
@dervus dervus Fix and clear 'construct-map' test data. d0867c0
@dervus dervus Port 'construct-custom' test data. 1254648
@dervus dervus Port 'construct-bool' test data. 6280fb9
@dervus dervus Port 'construct-int' test data. eac8cff
@dervus dervus Port 'construct-float' test data. d916c12
@dervus dervus Add tests for 'areEqualObjects' function. d0b2f7b
@dervus dervus Fix/rewrite 'areEqualObjects'. 33bb14b
@dervus dervus Improve constructor tests' error reporting. d275268
@dervus dervus Port 'construct-null' test data. 29a293c
@dervus dervus Port 'construct-seq' test data. 53e94af
@dervus dervus Port 'construct-pairs' test data. 0f6fa72
@dervus dervus Port 'construct-str' test data b823904
@dervus dervus Port 'construct-str-ascii' test data. 457461e
@dervus dervus Port 'construct-str-utf8' test data. a5947e8
@dervus dervus Port 'construct-set' test data. 4101246
@dervus dervus Port 'construct-value' test data. dbf5325
@dervus dervus Port 'construct-omap' test data. b923e48
@dervus dervus Port 'construct-timestamp' test data. 8fbd78a
@dervus dervus Port 'construct-merge' test data. 87c7853
@dervus dervus Replace Chai with Node's assert in the tests.
I just had very bad experience with Chai while porting constructor
tests. Chai's assertion errors seems be completely unhelpful, because
they can not tell where the error happen. Node's assert shows
the backtrace at least.
@dervus dervus Add missed blank line in functional/mark tests. b93fe80
@dervus dervus Remove broken test from functional/errors.
JS-YAML does not support reading from non-string resources, so this
test does not work anyway. It throws the expected error, but for
different reason.
@dervus dervus Small cleanup in js-yaml-test/common. b1f5b76
@dervus dervus Fix 'construct-bool' test. 25cae72
@dervus dervus Fix 'construct-custom' test. 9fe3371
@dervus dervus Export ReaderError from the reader module. ee79d22
@dervus dervus Port reader functional tests. 30cc7bd
@dervus dervus Move JS-YAML-TEST to test/support directory. 159d38c
@dervus dervus Clear the tests. e8c68ae
@dervus dervus Remove unused exports from test/support/common 474cdaa
@dervus dervus Move `areEqual` function to separate project. ef2f1ee
@dervus dervus Update package.json and Makefile 284c459
@dervus dervus Hook 'assert-full-equal' library. 2919dbd
@dervus dervus Remove unused imports in constructor tests a8489ca
@dervus dervus Clear reader tests. 81ff47a
@dervus dervus Refactor functional test helper 78010ff
@dervus dervus Refactor 'construct-bool.code' 0894e62
@dervus dervus Refactor 'construct-custom.code' 8e087a9
@dervus dervus Fix constructor tests 4c01d84
@dervus dervus Refactor 'construct-float.code' 8131901
@dervus dervus Refactor 'construct-int.code' 5220683
@dervus dervus Refactor 'construct-map.code' 3b52d20
@dervus dervus Refactor 'construct-merge.code' 6427b4d
@dervus dervus Refactor 'construct-null.code' ac5c129
@dervus dervus Refactor 'construct-omap.code' 4eae64d
@dervus dervus Refactor 'construct-pairs.code' 5bb16b2
@dervus dervus Refactor 'construct-seq.code' 4b95325
@dervus dervus Refactor 'construct-set.code' 52888eb
@dervus dervus Refactor 'construct-str.code' 4f129fd
@dervus dervus Refactor 'construct-str-ascii.code' 54d6661
@dervus dervus Refactor 'construct-str-utf8.code' 05886ed
@dervus dervus Refactor 'construct-timestamp.code' cc776ec
@dervus dervus Refactor 'construct-value.code' 1153f47
@dervus dervus Fix a typo in environment variable name c7dc874
@dervus dervus Port 'construct-binary' test data ca6cab6
@dervus dervus Port 'duplicate-key' test data 40a29c8
@dervus dervus Port 'duplicate-value-key' test data 7cd02d7
@dervus dervus Port 'duplicate-mapping-key' test data 2794350
@dervus dervus Port 'duplicate-merge-key' test data eb0a4e9
@dervus dervus Port 'utf8' test data d33c25d
@dervus dervus Port 'utf8-implicit' test data 4917bb8
@dervus dervus Style correction in 'utf8' test data d7861e2
@dervus dervus Port 'emitting-unacceptable-unicode-character-bug' 1f6362c
@dervus dervus Port 'invalid-single-quote-bug' test data f45599f
@dervus dervus Port 'more-floats' test data 12c2c9d
@dervus dervus Port 'negative-float-bug' test data 05974e7
@dervus dervus Port 'single-dot-is-not-float-bug' test data 492d6f0
@dervus dervus Port 'timestamp-bugs' test data 616e1ca
@dervus dervus Move Python-specific samples into the unsupported d01d119
@dervus dervus Move 'utf16{le,be}' samples into the unsupported 4fe6edc
@dervus dervus Move out 'float-representer-2.3-bug' sample 4ac58c2
@dervus dervus Port canonical loader/parser/scanner for the tests 3c93826
@dervus dervus Use `isNothing` in the tests code bf3dece
@dervus dervus Add missed `parse` function to the root module 116c2ae
@dervus dervus Port canonical loader/parser/scanner tests 2443daf
@dervus dervus Move `DataFile` class to the test utilities module c8525fd
@dervus dervus Some little changes in `makeClassConstructor` 85add0f
@dervus dervus Lint the tests ab05fc0
@dervus dervus Port issue tests 4f1b413
@dervus dervus Move all non-UTF8 samples to the unsupported 7f8b412
@dervus dervus Little style change in the functional test helper e2808ec
@dervus dervus Improve internal constructor/representer test API fdde9cb
@dervus dervus Add `construct-javascript-undefined` test b55dac1
@dervus dervus Add `construct-javascript-regexp` test 329c80c
@dervus dervus Add `construct-javascript-function` test 391d218
@dervus dervus Simplify issue tests a331240
@dervus dervus Use ASSERT-PARANOID-EQUAL 4b4f67a
@dervus dervus Embed ASSERT-PARANOID-EQUAL into the tests support 0fcbfbd
@dervus dervus Correct style in the JSHint inline declarations 6c33bed

@ixti ixti commented on the diff Dec 19, 2012

+var assert = require('assert');
+var jsyaml = require('../../lib/js-yaml');
+var _errors = require('../../lib/js-yaml/errors');
+var _functional = require('../support/functional');

ixti Dec 19, 2012


why these variables starts with _?

@ixti ixti and 1 other commented on an outdated diff Dec 19, 2012

+ assert.strictEqual(actual.length, expected.length);
+ assert.strictEqual(
+ actual[0](),
+ expected[0]());
+ assert.strictEqual(
+ actual[1](10, 20),
+ expected[1](10, 20));
+ assert.deepEqual(
+ actual[2]('book'),
+ expected[2]('book'));
+testHandler.getExpectedData = function getExpectedData() {

ixti Dec 19, 2012


Why doing this via function? why not just export an object with two properties:

module.export = {
  test: function (actual) { /*...*/ },
  expected: [
    // ...

dervus Dec 20, 2012


This is very special case. Since there is no way to compare functions' source AST, we have to compare their execution results. All of the rest samples return just a plain object (or an array, or a string), so it is not a good idea to use such an interface with all of them. Since there is no regular way to compare functions, the constructor test handler interpret them as a "self-testing" assertors.

getExpectedData is separated from the assertor code because of upcoming representer tests which need some actual data to dump. It is also a function in order to give it more flexibility. Hm... Maybe it should be a plain object because regular samples return plain objects.


ixti commented Dec 19, 2012

Can you please align = in a same column upon variables declarations that re going vertically:

var foo    = require('foo');
var bar    = require('bar');
var mooboo = require('mooo');

@ixti ixti commented on an outdated diff Dec 19, 2012

@@ -0,0 +1,23 @@
+'use strict';
+var assert = require('assert');
+var inspectors = require('./assert-paranoid-equal/inspectors');
+var Context = require('./assert-paranoid-equal/context');
+function paranoidEqual(value1, value2) {

ixti Dec 19, 2012


Needs description.


dervus commented Dec 20, 2012

Hm... Seems like Travis don't like shims. I do not exactly understand the reason of this build fail.


dervus commented Dec 20, 2012

Yeah. Seems it was Travis' bug.


dervus commented Dec 20, 2012

If you have no more remarks, it is ready to merge.

@ixti ixti added a commit that referenced this pull request Dec 20, 2012

@ixti ixti Merge pull request #57 from dervus/mocha
Port the tests to Mocha. And some of the missed PyYAML tests.

@ixti ixti merged commit ca5722f into nodeca:master Dec 20, 2012

1 check passed

default The Travis build passed

@dervus dervus deleted the unknown repository branch Dec 21, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment