UNPKG

sku-pg

Version:

Skulpt is a Javascript implementation of Python 2.x. Python that runs in your browser!

102 lines (82 loc) 3.24 kB
<!DOCTYPE html> <html> <!-- Copyright 2012 The Closure Library Authors. All Rights Reserved. Use of this source code is governed by the Apache License, Version 2.0. See the COPYING file for details. --> <head> <title>Closure Unit Tests - String matchers</title> <script src="../../base.js"></script> <script> goog.require('goog.labs.testing.ContainsStringMatcher'); goog.require('goog.labs.testing.EndsWithMatcher'); goog.require('goog.labs.testing.EqualsMatcher'); goog.require('goog.labs.testing.EqualToIgnoringWhitespaceMatcher'); goog.require('goog.labs.testing.RegexMatcher'); goog.require('goog.labs.testing.StartsWithMatcher'); goog.require('goog.labs.testing.StringContainsInOrderMatcher'); goog.require('goog.labs.testing.assertThat'); goog.require('goog.testing.jsunit'); </script> </head> <body> <script> function testContainsString() { goog.labs.testing.assertThat('hello', containsString('ell'), 'hello contains ell'); assertMatcherError(function() { goog.labs.testing.assertThat('hello', containsString('world!')); }, 'containsString should throw exception when it fails'); } function testEndsWith() { goog.labs.testing.assertThat('hello', endsWith('llo'), 'hello ends with llo'); assertMatcherError(function() { goog.labs.testing.assertThat('minutes', endsWith('midnight')); }, 'endsWith should throw exception when it fails'); } function testEqualToIgnoringWhitespace() { goog.labs.testing.assertThat(' h\n EL L\tO', equalToIgnoringWhitespace("h el l o"), '" h EL L\tO " is equal to "h el l o"'); assertMatcherError(function() { goog.labs.testing.assertThat('hybrid', equalToIgnoringWhitespace('theory')); }, 'equalToIgnoringWhitespace should throw exception when it fails'); } function testEquals() { goog.labs.testing.assertThat('hello', equals('hello'), 'hello equals hello'); assertMatcherError(function() { goog.labs.testing.assertThat('thousand', equals('suns')); }, 'equals should throw exception when it fails'); } function testStartsWith() { goog.labs.testing.assertThat('hello', startsWith('hel'), 'hello starts with hel'); assertMatcherError(function() { goog.labs.testing.assertThat('linkin', startsWith('park')); }, 'startsWith should throw exception when it fails'); } function testStringContainsInOrder() { goog.labs.testing.assertThat('hello', stringContainsInOrder(['h', 'el', 'el', 'l', 'o']), 'hello contains in order: [h, el, l, o]'); assertMatcherError(function() { goog.labs.testing.assertThat('hybrid', stringContainsInOrder(['hy', 'brid', 'theory'])); }, 'stringContainsInOrder should throw exception when it fails'); } function testMatchesRegex() { goog.labs.testing.assertThat('foobar', matchesRegex(/foobar/)); goog.labs.testing.assertThat('foobar', matchesRegex(/oobar/)); assertMatcherError(function() { goog.labs.testing.assertThat('foo', matchesRegex(/^foobar$/)); }, 'matchesRegex should throw exception when it fails'); } function assertMatcherError(callable, errorString) { var e = assertThrows(errorString || 'callable throws exception', callable); assertTrue(e instanceof goog.labs.testing.MatcherError); } </script> </body> </html>