UNPKG

sku-pg

Version:

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

79 lines (65 loc) 2.1 kB
<!DOCTYPE html> <html> <!-- Copyright 2011 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> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Closure Unit Tests - goog.testing.MockStorage</title> <script src="../base.js"></script> <script> goog.require('goog.testing.MockStorage'); goog.require('goog.testing.jsunit'); </script> </head> <body> <script> var instance; function setUp() { instance = new goog.testing.MockStorage(); } /** * Tests the MockStorage interface. */ function testMockStorage() { assertEquals(0, instance.length); instance.setItem('foo', 'bar'); assertEquals(1, instance.length); assertEquals('bar', instance.getItem('foo')); assertEquals('foo', instance.key(0)); instance.setItem('foo', 'baz'); assertEquals('baz', instance.getItem('foo')); instance.setItem('goo', 'gl'); assertEquals(2, instance.length); assertEquals('gl', instance.getItem('goo')); assertEquals('goo', instance.key(1)); assertNull(instance.getItem('poogle')); instance.removeItem('foo'); assertEquals(1, instance.length); assertEquals('goo', instance.key(0)); instance.setItem('a', 12); assertEquals('12', instance.getItem('a')); instance.setItem('b', false); assertEquals('false', instance.getItem('b')); instance.setItem('c', {a: 1, b: 12}); assertEquals('[object Object]', instance.getItem('c')); instance.clear(); assertEquals(0, instance.length); // Test some special cases. instance.setItem('emptyString', ''); assertEquals('', instance.getItem('emptyString')); instance.setItem('isNull', null); assertEquals('null', instance.getItem('isNull')) instance.setItem('isUndefined', undefined); assertEquals('undefined', instance.getItem('isUndefined')) instance.setItem('', 'empty key'); assertEquals('empty key', instance.getItem('')); assertEquals(4, instance.length); } </script> </body> </html>