Example #1
0
test('unicode', function(t) {
  var m = ohm.grammar('M {}');

  test('recognition', function(t) {
    assertSucceeds(t, m.match('a', 'lower'));
    assertSucceeds(t, m.match('\u00E9', 'lower'), 'small letter e with acute');
    assertSucceeds(t, m.match('\u03C9', 'lower'), 'Greek small letter Omega');
    assertFails(t, m.match('`', 'lower'));
    assertFails(t, m.match('\u20AC', 'lower'), 'Euro sign');
    assertFails(t, m.match('\u01C0', 'lower'), 'Latin letter dental click');

    assertSucceeds(t, m.match('Z', 'upper'));
    assertSucceeds(t, m.match('\u03A9', 'upper'), 'Greek capital letter Omega');
    assertFails(t, m.match('[', 'upper'));
    assertFails(t, m.match('\u20AC', 'upper'), 'Euro sign');
    assertFails(t, m.match('\u01C0', 'upper'), 'Latin letter dental click');

    assertSucceeds(t, m.match('\u01C0', 'letter'), 'dental click is a letter');
    assertSucceeds(t, m.match(['\u01C0'], 'letter'), 'dental click in a list');
    t.end();
  });

  test('semantic actions', function(t) {
    var s = m.semantics().addAttribute('v', {
      _terminal: function() {
        return this.primitiveValue + this.primitiveValue;
      }
    });
    var r = m.match('\u01C0', 'letter');
    t.equal(s(r).v, '\u01C0\u01C0');
    t.end();
  });
  t.end();
});
Example #2
0
tap(initProjects({1: true}), (projects) => {
  const timestamp = Date.now();
  const repoName = 'Page-Title-abc123';
  test('gist export', reducerTest(
    reducer,
    projects,
    partial(
      projectExported,
      'https://gist.github.com/abc123',
      'gist',
      '1',
      timestamp,
    ),
    projects,
    'is a no-op',
  ));
  test('repo export', reducerTest(
    reducer,
    projects,
    partial(
      projectExported,
      'https://github.com/usernmaer/Page-Title-abc123',
      'repo',
      '1',
      {name: repoName},
      timestamp,
    ),
    projects.setIn(['1', 'updatedAt'], timestamp).
      setIn(['1', 'externalLocations', 'githubRepoName'], repoName),
    'stores the repo name',
  ));
});
Example #3
0
test('char', function(t) {
  var m = ohm.grammar('M { bang = "!" }');

  test('direct match, no stream', function(t) {
    it('recognition', function() {
      assertSucceeds(t, m.match('!'));
      assertFails(t, m.match('!a'));
      assertFails(t, m.match(5));
      assertFails(t, m.match(''));
    });

    it('semantic actions', function() {
      var s = m.semantics().addAttribute('v', {});
      var cst = m.match('!');
      t.equal(s(cst).v, '!');
    });
    t.end();
  });

  test('match in string stream', function(t) {
    it('recognition', function() {
      assertSucceeds(t, m.match('!'));
      assertFails(t, m.match('a'));
      assertFails(t, m.match(''));
    });

    it('semantic actions', function() {
      var s = m.semantics().addAttribute('v', {});
      var cst = m.match('!');
      t.equal(s(cst).v, '!');
    });
    t.end();
  });
  t.end();
});
Example #4
0
test('ranges', function(t) {
  var m = ohm.grammar('M { charRange = "0".."9"  intRange = 5..131  strRange = ["bb".."foobar"] }');
  var s = m.semantics().addAttribute('v', {
    _terminal: function() {
      return this.primitiveValue;
    }
  });

  test('recognition', function(t) {
    assertSucceeds(t, m.match('6', 'charRange'));
    assertFails(t, m.match('x', 'charRange'));
    assertFails(t, m.match(6, 'charRange'));

    assertSucceeds(t, m.match(5, 'intRange'));
    assertSucceeds(t, m.match(6, 'intRange'));
    assertSucceeds(t, m.match(120, 'intRange'));
    assertSucceeds(t, m.match(131, 'intRange'));
    assertFails(t, m.match(132, 'intRange'));
    assertFails(t, m.match('x', 'intRange'));
    assertFails(t, m.match('100', 'intRange'));

    assertFails(t, m.match(['aa'], 'strRange'));
    assertSucceeds(t, m.match(['bb'], 'strRange'));
    assertSucceeds(t, m.match(['bc'], 'strRange'));
    assertSucceeds(t, m.match(['cc'], 'strRange'));
    assertSucceeds(t, m.match(['ccsa'], 'strRange'));
    assertSucceeds(t, m.match(['doo-a-dee-dee'], 'strRange'));
    assertSucceeds(t, m.match(['foo'], 'strRange'));
    assertSucceeds(t, m.match(['foobar'], 'strRange'));
    assertSucceeds(t, m.match(['foobaar'], 'strRange'));
    assertFails(t, m.match(['foobarr'], 'strRange'));
    assertFails(t, m.match(['xxasdf'], 'strRange'));
    assertFails(t, m.match([4]));
    assertFails(t, m.match(['foo']));

    t.end();
  });

  test('semantic actions', function(t) {
    t.equal(s(m.match('4', 'charRange')).v, '4');
    t.equal(s(m.match(40, 'intRange')).v, 40);
    t.equal(s(m.match(['foo'], 'strRange')).v, 'foo');
    t.end();
  });

  t.end();
});
Example #5
0
  test('any', function(t) {
    var m = ohm.grammar('M { }');
    var s = m.semantics().addAttribute('v', {
      _terminal: function() {
        return this.primitiveValue;
      }
    });

    test('direct match, no stream', function(t) {
      it('recognition', function() {
        assertSucceeds(t, m.match(5, 'any'), 'any matches 5');
        assertSucceeds(t, m.match(null, 'any'), 'any matches null');
      });

      it('semantic actions', function() {
        t.equal(s(m.match(5, 'any')).v, 5, 'SA on 5');
        t.equal(s(m.match(null, 'any')).v, null, 'SA on null');
      });
      t.end();
    });

    test('match in string stream', function(t) {
      it('recognition', function() {
        assertSucceeds(t, m.match('5', 'any'));
        assertFails(t, m.match('', 'any'));
      });

      it('semantic actions', function() {
        t.equal(s(m.match('5', 'any')).v, '5');
      });
      t.end();
    });

    test('match in list stream', function(t) {
      it('recognition', function() {
        assertSucceeds(t, m.match(['123'], 'any'));
      });

      it('semantic actions', function() {
        t.deepEqual(s(m.match(['123'], 'any')).v, ['123']);
      });
      t.end();
    });
    t.end();
  });
Example #6
0
test('string', function(t) {
  var m = ohm.grammar('M { foo = "foo\\b\\n\\r\\t\\\\\\\"\\u01bcff\\x8f" }');
  var s = m.semantics().addAttribute('v', {
    _terminal: function() {
      return this.primitiveValue;
    }
  });

  test('direct match, no stream', function(t) {
    it('recognition', function() {
      assertSucceeds(t, m.match('foo\b\n\r\t\\"\u01bcff\x8f'));
      assertFails(t, m.match('foo1'));
      assertFails(t, m.match('bar'));
      assertFails(t, m.match(null));
    });

    it('semantic actions', function() {
      var cst = m.match('foo\b\n\r\t\\"\u01bcff\x8f');
      t.equal(s(cst).v, 'foo\b\n\r\t\\"\u01bcff\x8f');
    });

    it('unrecognized escape characters are parse errors', function() {
      t.throws(
          function() { ohm.grammar('G { r = "\\w" }'); },
          'Expected \"\\\"\"');
    });

    t.end();
  });

  test('match in string stream', function(t) {
    it('recognition', function() {
      assertSucceeds(t, m.match('foo\b\n\r\t\\"\u01bcff\x8f'));
      assertFails(t, m.match('foo1'));
      assertFails(t, m.match('bar'));
    });

    it('semantic actions', function() {
      var cst = m.match('foo\b\n\r\t\\"\u01bcff\x8f');
      t.equal(s(cst).v, 'foo\b\n\r\t\\"\u01bcff\x8f');
    });
    t.end();
  });
  t.end();
});
Example #7
0
 projects => test('userLoggedOut', reducerTest(
   rootReducer,
   Immutable.fromJS({currentProject: {projectKey: '1'}, projects}),
   userLoggedOut,
   Immutable.fromJS({
     currentProject: {projectKey: '1'},
     projects: projects.take(1),
   }),
 )),
Example #8
0
function test (desc, fn) {
  tapeCatch(desc, function (t) {
    try {
      setTimeout(function () { fn(t) }, 0)
    } catch (err) {
      t.fail(err)
    }
  })
}
Example #9
0
 initProjects({1: true}), projects =>
   test('unhideComponent', reducerTest(
     reducer,
     projects.updateIn(
       ['1', 'hiddenUIComponents'],
       components => components.add('output'),
     ),
     partial(unhideComponent, '1', 'output', now),
     projects,
   )),
invalidConnections.forEach(function(conn) {
    test(`should fail with invalid connection: ${conn.desc}`, function(t) {
        const mycro = { log: utils.log, connections: conn.connections };
        hook.call(mycro, function(err) {
            fp.attempt(function() {
                t.ok(err instanceof Error, 'should error');
            });
            t.end();
        });
    });
});
Example #11
0
tap({url: 'https://gists.github.com/12345abc', exportType: 'gist'}, (payload) => {
  test('projectExportNotDisplayed', reducerTest(
    reducer,
    initialState,
    partial(projectExportNotDisplayed, payload.url, payload.exportType),
    withNotification(
      'project-export-complete',
      'notice',
      {url: payload.url, exportType: payload.exportType},
    ),
  ));
});
function testFlexGrowAfterDrag(description, before, after, expected) {
  test(description, (assert) => {
    const actual = calculateFlexGrowAfterDrag(before, after);
    assert.ok(
      arraysAlmostEqual(actual, expected),
      `Expected flex grow ${expected.join(',')} from previous\
      ${before.currentFlexGrow},${after.currentFlexGrow}; \
      got ${actual.join(',')}`,
    );
    assert.end();
  });
}
Example #13
0
 rehydratedProject =>
   test('projectRestoredFromLastSession', reducerTest(
     reducer,
     states.initial,
     partial(
       projectRestoredFromLastSession,
       rehydratedProject,
     ),
     states.initial.set(
       rehydratedProject.projectKey,
       Project.fromJS(rehydratedProject),
     ),
   )),
Example #14
0
 projects => test(
   'toggleLibrary',
   reducerTest(
     reducer,
     projects,
     partial(toggleLibrary, '1', 'jquery', now),
     projects.update(
       '1',
       projectIn =>
         projectIn.set('enabledLibraries', new Immutable.Set(['jquery'])).
           set('updatedAt', now),
     ),
   ),
 ),
Example #15
0
 (firebaseUser) => {
   test('accountMigrationComplete', reducerTest(
     reducer,
     states.initial,
     partial(accountMigrationComplete, firebaseUser, {}, projectsIn),
     projectsIn.reduce(
       (map, projectIn) => map.set(
         projectIn.projectKey,
         buildProject(
           projectIn.projectKey,
           projectIn.sources,
         ).set('updatedAt', projectIn.updatedAt),
       ),
       new Immutable.Map(),
     ),
   ));
 },
Example #16
0
tap(initProjects({1: true}), (projects) => {
  const timestamp = Date.now();
  test('focusLine', reducerTest(
    rootReducer,
    Immutable.fromJS({
      projects: projects.updateIn(
        ['1', 'hiddenUIComponents'],
        components => components.add('editor.javascript'),
      ),
      currentProject: {projectKey: '1'},
    }),
    partial(focusLine, 'editor.javascript', 1, 1, timestamp),
    Immutable.fromJS({
      projects: projects.setIn(['1', 'updatedAt'], timestamp),
      currentProject: {projectKey: '1'},
    }),
  ));
});
module.exports = function tests(locationHash, delayAfterInitialRouteChange) {
	function getRoute(options) {
		return options ? makeRouter(options, locationHash) : makeRouter(locationHash)
	}

	test('browser back button triggers a hashchange', function(t) {
		t.timeoutAfter(4000)
		locationHash.go('')
		setTimeout(function() {
			var route = getRoute()
			var originVisits = 0
			var otherPlaceVisits = 0

			route.add('/origin', function() {
				originVisits++
				if (originVisits === 1) {
					setTimeout(function() {
						locationHash.go('/other-place')
					}, delayAfterInitialRouteChange)
				} else {
					t.equal(originVisits, 2, 'Second visit to the origin route')
					route.stop()
					t.end()
				}
			})

			route.add('/other-place', function() {
				otherPlaceVisits++
				if (otherPlaceVisits === 1) {
					setTimeout(function() {
						window.history.back()
					}, delayAfterInitialRouteChange)
				} else {
					t.fail()
				}
			})

			locationHash.go('/origin')
		}, delayAfterInitialRouteChange)
	})
}
Example #18
0
tap([project(), project()], (projectsIn) => {
  test('projectsLoaded', reducerTest(
    reducer,
    states.initial,
    partial(projectsLoaded, projectsIn),
    projectsIn.reduce(
      (map, projectIn) => map.set(
        projectIn.projectKey,
        buildProject(
          projectIn.projectKey,
          projectIn.sources,
        ).set('updatedAt', projectIn.updatedAt),
      ),
      new Immutable.Map(),
    ),
  ));

  tap(
    {providerData: [{providerId: 'google.com'}, {providerId: 'github.com'}]},
    (firebaseUser) => {
      test('accountMigrationComplete', reducerTest(
        reducer,
        states.initial,
        partial(accountMigrationComplete, firebaseUser, {}, projectsIn),
        projectsIn.reduce(
          (map, projectIn) => map.set(
            projectIn.projectKey,
            buildProject(
              projectIn.projectKey,
              projectIn.sources,
            ).set('updatedAt', projectIn.updatedAt),
          ),
          new Immutable.Map(),
        ),
      ));
    },
  );
});
Example #19
0
tap(project(), (importedProject) => {
  const snapshotProjectKey = '123454321';

  test('snapshotImported', reducerTest(
    reducer,
    states.initial,
    partial(
      snapshotImported,
      snapshotProjectKey,
      importedProject,
    ),
    states.initial.set(
      snapshotProjectKey,
      Project.fromJS(
        assign(
          {},
          importedProject,
          {projectKey: snapshotProjectKey, updatedAt: null},
        ),
      ),
    ),
  ));
});
Example #20
0
const test = require('tape-catch');

import sequentialReadableStream from './utils/sequential-rs';
import duckTypedPassThroughTransform from './utils/duck-typed-pass-through-transform';
import readableStreamToArray from './utils/readable-stream-to-array';

test('Piping through a duck-typed pass-through transform stream works', t => {
  t.plan(1);

  const readableEnd = sequentialReadableStream(5).pipeThrough(duckTypedPassThroughTransform());

  readableStreamToArray(readableEnd).then(chunks => t.deepEqual(chunks, [1, 2, 3, 4, 5]));
});

test('Piping through an identity transform stream will close the destination when the source closes', t => {
  t.plan(1);

  const rs = new ReadableStream({
    start(c) {
      c.enqueue('a');
      c.enqueue('b');
      c.enqueue('c');
      c.close();
    }
  });

  const ts = new TransformStream({
    transform(chunk, enqueue, done) {
      enqueue(chunk);
      done();
    }
Example #21
0
import test from 'tape-catch';
import React from 'react';

import shallow from '../../testUtils/shallow';
import ColorPicker from './index.js';

test('Default modal container renders properly', t => {

  const { result } = shallow(<ColorPicker />);

  t.equal(result.type, 'span', 'should be a span');

  t.end();
});
Example #22
0
// svg-test.js
var tape = require('tape-catch'),
    jsdom = require('jsdom'),
    d3_svg = require('../');

tape('d3_svg creates an svg element', function(test) {
  var document = jsdom.jsdom();
  global.document = document;
  var svg = d3_svg.create('body');
  test.ok(svg, 'svg element exists');
  delete global.document;
  test.end();
});

tape('d3_svg can set height and with on svg element', function(test) {
  var document = jsdom.jsdom();
  global.document = document;
  var svg = d3_svg.create('body', {width: 100, height: 50});
  test.ok(svg, 'svg element exists');
  test.ok(svg.attr('width', 100), 'svg element has correct width');
  test.ok(svg.attr('height', 50), 'svg element has correct height');
  delete global.document;
  test.end();
});

tape('d3_svg creates an svg element that can be appended to', function(test) {
  var document = jsdom.jsdom();
  global.document = document;
  var svg = d3_svg.create('body');
  var g = svg.append('g');
  test.ok(g, 'g element exists');
Example #23
0
import test from "tape-catch";
import sinon from "sinon";
import Store from "../../../src/store";

test("loadAll must throw an error if it is called when there isn't an adapter", function (t) {
  var store = new Store();
  t.plan(1);
  t.throws(function () {
    store.loadAll();
  }, /Adapter missing\. Specify an adapter when creating the store: `var store = new Store\(adapter\);`/);
});

test("loadAll must call the load method provided by the adapter", function (t) {
  var a = {};
  var adatper = {
    load: sinon.spy(function () {
      return a;
    })
  };
  var store = new Store(adatper);
  var type = "foo";
  var options = {};
  var result;
  t.plan(6);
  t.doesNotThrow(function () {
    result = store.loadAll(type, options);
  }, "should not throw an error");
  t.equal(adatper.load.lastCall.args[0], store);
  t.equal(adatper.load.lastCall.args[1], type);
  t.equal(adatper.load.lastCall.args[2], null);
  t.equal(adatper.load.lastCall.args[3], options);
Example #24
0
import test from 'tape-catch';
import React from 'react';

import shallow from '../../testUtils/shallow';
import { Dropdown } from './index.js';

test('<Dropdown />', t => {

  const { instance, result } = shallow(<Dropdown onChange={()=>{}}/>);
  const children = instance._renderChildren('a');

  t.equal(result.type, 'ul', 'should be an unordered list');
  t.equal(children.length, 1, 'should have one child');
  t.equal(children[0].type, 'li', 'should have a child li');
  t.equal(children[0].props.children, 'a', 'child should be a');
  t.equal(children[0].props.className, 'option', 'child should be a class of option');

  t.end();
});
Example #25
0
      zoom: 15.5
    }
  },
  {
    mapState: {
      width: 793,
      height: 775,
      latitude: 50.751537058389985,
      longitude: 42.42694203247012,
      zoom: 15.5
    }
  }
];

test('Viewport#imports', t => {
  t.ok(Viewport, 'Viewport import ok');
  t.end();
});

test('Viewport#constructor', t => {
  t.ok(new Viewport() instanceof Viewport, 'Created new Viewport with default args');
  t.ok(new Viewport(TEST_DATA.viewport) instanceof Viewport, 'Created new Viewport with test args');
  t.end();
});

test('Viewport#constructor - 0 width/height', t => {
  const viewport = new Viewport(
    Object.assign({}, TEST_DATA.viewport, {
      width: 0,
      height: 0
    })
  );
Example #26
0
tape('Exists: Library', { skip: false }, (describe) => {
  const path = require('path');

  const lib = require('../lib/exists');

  const successTest = async (assert, testPath) => {
    try {
      const verifiedPath = await lib.pathExists(testPath);

      const normalTestPath = path.normalize(testPath);
      assert.ok(verifiedPath.endsWith(normalTestPath), `Verified path (${verifiedPath}) matches test path (${normalTestPath})`);
    } catch (error) {
      assert.fail(error);
    }

    assert.end();
  };

  function failureTest(assert, testPath) {
    lib.pathExists(testPath)
      .then(() => {
        assert.fail(`File system found a fake folder (${testPath})`);
        assert.end();
      })
      .catch((error) => {
        assert.equal(error.isBoom, true, 'Rejected promise is a boom error');
        assert.end();
      });
  }

  describe.test('* Real relative file exists', (assert) => {
    const testPath = 'test/fixtures/exists.txt';
    successTest(assert, testPath);
  });

  describe.test('* Real relative folder exists', (assert) => {
    const testPath = 'test/fixtures';
    successTest(assert, testPath);
  });

  describe.test('* Real absolute file exists', (assert) => {
    const testPath = '/test/fixtures/exists.txt';
    successTest(assert, testPath);
  });

  describe.test('* Real absolute folder exists', (assert) => {
    const testPath = '/test/fixtures';
    successTest(assert, testPath);
  });

  describe.test('* Real root absolute file exists', (assert) => {
    const testPath = path.join(__dirname, '../../../../public/test/fixtures/exists.txt');
    successTest(assert, testPath);
  });

  describe.test('* Real root absolute folder exists', (assert) => {
    const testPath = path.join(__dirname, '../../../../public/test/fixtures');
    successTest(assert, testPath);
  });

  describe.test('* Fake absolute path does not exists', (assert) => {
    const testPath = '/test/fixtures/fakeFolder';
    failureTest(assert, testPath);
  });

  describe.test('* Safe path throws error', (assert) => {
    const testPath = true;
    failureTest(assert, testPath);
  });
});
Example #27
0
import test from 'tape-catch';
import Component from '@deck.gl/core/lifecycle/component';

/* global fetch */
const EMPTY_ARRAY = Object.freeze([]);

const defaultProps = {
  // data: Special handling for null, see below
  data: {type: 'data', value: EMPTY_ARRAY, async: true},
  dataComparator: null,
  dataTransform: data => data,
  fetch: url => fetch(url).then(response => response.json())
};

class TestComponent extends Component {
  constructor(...props) {
    super(...props);
  }
}

TestComponent.defaultProps = defaultProps;

test('Component#imports', t => {
  t.ok(Component, 'Component import ok');
  t.end();
});
Example #28
0
// --------------------------------------------------------------------

function toGrammar(recipeString) {
  return ohm.makeRecipe(eval(recipeString));  // eslint-disable-line no-eval
}

// --------------------------------------------------------------------
// Tests
// --------------------------------------------------------------------

test('simple recipes', function(t) {
  var g = ohm.grammar('G{}');
  t.ok(toGrammar(g.toRecipe()).match('', 'end'), 'grammar with no rules');

  g = ohm.grammar('G { start = end }');
  t.ok(toGrammar(g.toRecipe()).match('', 'start'), 'grammar with one rule');

  g = ohm.grammar('MyGrammar { start = x\n  x = "a" }');
  t.ok(toGrammar(g.toRecipe()).match('a', 'start'), 'grammar with multiple rules');

  t.end();
});

test('recipes with supergrammars', function(t) {
  var ns = ohm.createNamespace();
  ns.G = ohm.grammar('G { start = end }');
  ns.G2 = ohm.grammar('G2 <: G { start := "a" }', ns);

  t.ok(toGrammar(ns.G2.toRecipe()).match('a', 'start'), 'one level of inheritance');

  ns.G3 = ohm.grammar('G3 <: G2 { begin = a b\n  a = "a"\n  b = "b" }', ns);
  t.ok(toGrammar(ns.G3.toRecipe()).match('ab', 'begin'), 'two levels of inheritance');
Example #29
0
'use strict'
var test = require('tape-catch')
var build = require('./')
var plainOldWs

test('simple test', function (t) {
  plainOldWs = build()
  t.equal(plainOldWs.theOne(), 1, 'the one is 1')
  t.end()
})
  },
  {
    title: 'unprojectFlat (corner)',
    func: 'unprojectFlat',
    input: [236647, 572888],
    expected: [-122.5501905, 37.830127124]
  }
];

test('Viewport constructor', t => {
  const viewport = new WebMercatorViewport(viewportProps);

  t.ok(viewport, 'Viewport construction successful');

  const viewState = {};
  Object.keys(viewportProps).forEach(key => {
    viewState[key] = viewport[key];
  });

  t.deepEquals(viewState, viewportProps, 'Viewport props assigned');
  t.end();
});

test('Viewport projection', t => {
  const viewport = new WebMercatorViewport(viewportProps);

  TEST_CASES.forEach(({title, func, input, expected}) => {
    const output = viewport[func](input);
    t.deepEquals(
      output.map(x => toLowPrecision(x)),
      expected.map(x => toLowPrecision(x)),