Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: test/tests/typedObjects.js

Issue 5665229014827008: Issue 150 - [Typed objects] Implement string type (Closed)
Patch Set: Created May 16, 2014, 1:47 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« lib/typedObjects/stringType.js ('K') | « test/index.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 equal(array6.arrayByteOffset, 0, "Second large array is allocated at zero of fset"); 672 equal(array6.arrayByteOffset, 0, "Second large array is allocated at zero of fset");
673 673
674 array5.release(); 674 array5.release();
675 array5 = uint32Array(9); 675 array5 = uint32Array(9);
676 equal(array5.arrayBufferIndex, 5, "Buffer indexes for large arrays aren't re used"); 676 equal(array5.arrayBufferIndex, 5, "Buffer indexes for large arrays aren't re used");
677 equal(array5.arrayByteOffset, 0, "Large array is allocated at zero offset"); 677 equal(array5.arrayByteOffset, 0, "Large array is allocated at zero offset");
678 678
679 for (let array of [array1, array2, array3, array4, array5]) 679 for (let array of [array1, array2, array3, array4, array5])
680 array.release(); 680 array.release();
681 }); 681 });
682
683 test("String type", function()
684 {
685 let {string} = require("typedObjects");
686
687 let s1 = string();
688 ok(s1, "String created without parameters");
689 equal(s1.length, 0, "String length is zero");
690 equal(s1.toString(), "", "JavaScript representation is empty string");
691 s1.release();
692
693 let s2 = string(4);
694 ok(s2, "String with particular length created");
695 equal(s2.length, 4, "String length set correctly");
696 for (let i = 0; i < s2.length; i++)
697 s2.set(i, i + 0xF000);
698 equal(s2.toString(), "\uF000\uF001\uF002\uF003", "JavaScript representation is correct");
699 s2.release();
700
701 let s3 = string("test");
702 ok(s3, "String created from JS string");
703 equal(s3.length, 4, "String length set correctly");
704 equal(s3.get(2), "s".charCodeAt(0), "Array items represent string letters");
705 equal(s3.toString(), "test", "JavaScript representation is correct");
706 s3.release();
707
708 let s4 = string("somelongstring", 2, 6);
709 ok(s4, "String created as JS substring");
710 equal(s4.length, 6, "String length set correctly");
711 equal(s4.toString(), "melong", "JavaScript representation is correct");
712 s4.release();
713
714 let s5 = string("abc", 2, 6);
715 ok(s5, "String created as JS substring with excessive length parameter");
716 equal(s5.length, 1, "String length set correctly");
717 equal(s5.toString(), "c", "JavaScript representation is correct");
718 s5.release();
719
720 let s6 = string("abc", 8, 1);
721 ok(s6, "String created as JS substring with too large offset parameter");
722 equal(s6.length, 0, "String length set correctly");
723 equal(s6.toString(), "", "JavaScript representation is correct");
724 s6.release();
725
726 let s7 = string("abc", 1);
727 ok(s7, "String created as JS substring without length parameter");
728 equal(s7.length, 2, "String length set correctly");
729 equal(s7.toString(), "bc", "JavaScript representation is correct");
730 s7.release();
731
732 let s8 = string("somelongstring");
733 let s9 = string(s8, 2, 6);
734 ok(s9, "String created as typed substring");
735 equal(s9.length, 6, "String length set correctly");
736 equal(s9.toString(), "melong", "JavaScript representation is correct");
737 s9.release();
738
739 let s10 = string(s8, 4, 20);
740 ok(s10, "String created as typed substring with excessive length parameter") ;
741 equal(s10.length, 10, "String length set correctly");
742 equal(s10.toString(), "longstring", "JavaScript representation is correct");
743 s10.release();
744
745 let s11 = string(s8, 20, 1);
746 ok(s11, "String created as typed substring with too large offset parameter") ;
747 equal(s11.length, 0, "String length set correctly");
748 equal(s11.toString(), "", "JavaScript representation is correct");
749 s11.release();
750
751 let s12 = string(s8, 4);
752 ok(s12, "String created as typed substring without length parameter");
753 equal(s12.length, 10, "String length set correctly");
754 equal(s12.toString(), "longstring", "JavaScript representation is correct");
755 s12.release();
756 s8.release();
757 });
682 })(); 758 })();
OLDNEW
« lib/typedObjects/stringType.js ('K') | « test/index.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld