Best JavaScript code snippet using wpt
encoding_test.py
Source:encoding_test.py
...3from pycoin import encoding4from pycoin.serialize import h2b5class EncodingTestCase(unittest.TestCase):6 def test_to_from_long(self):7 def do_test(as_int, prefix, as_rep, base):8 self.assertEqual((as_int, prefix), encoding.to_long(base, encoding.byte_to_int, as_rep))9 self.assertEqual(as_rep, encoding.from_long(as_int, prefix, base, lambda v:v))10 do_test(10000101, 2, h2b("00009896e5"), 256)11 do_test(10000101, 3, h2b("0000009896e5"), 256)12 do_test(1460765565493402645157733592332121663123460211377, 1, b'\0\xff\xde\xfeOHu\xcf\x11\x9f\xc3\xd8\xf4\xa0\x9a\xe3~\xc4\xccB\xb1', 256)13 def test_to_bytes_32(self):14 for i in range(256):15 v = encoding.to_bytes_32(i)16 self.assertEqual(v, b'\0' * 31 + bytes(bytearray([i])))17 for i in range(256,512):18 v = encoding.to_bytes_32(i)19 self.assertEqual(v, b'\0' * 30 + bytes(bytearray([1, i&0xff])))20 def test_to_from_base58(self):21 def do_test(as_text, as_bin):22 self.assertEqual(as_bin, encoding.a2b_base58(as_text))23 self.assertEqual(as_text, encoding.b2a_base58(as_bin))24 do_test("1abcdefghijkmnpqrst", b'\x00\x01\x93\\|\xf2*\xb9\xbe\x19b\xae\xe4\x8c{')25 do_test("1CASrvcpMMTa4dz4DmYtAqcegCtdkhjvdn", b'\x00zr\xb6\xfac\xde6\xc4\xab\xc6\nh\xb5-\x7f3\xe3\xd7\xcd>\xc4\xba\xbd9')26 do_test("1111111111111111aaaa11aa",27 b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00CnzQ)\x0b')28 do_test("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",29 b'\x00\x01\x11\xd3\x8e_\xc9\x07\x1f\xfc\xd2\x0bJv<\xc9\xaeO%+\xb4\xe4\x8f\xd6j\x83^%*\xda\x93\xffH\rm\xd4=\xc6*d\x11U\xa5')30 def test_to_from_hashed_base58(self):31 def do_test(as_text, as_bin):32 self.assertEqual(as_text, encoding.b2a_hashed_base58(as_bin))33 self.assertEqual(as_bin, encoding.a2b_hashed_base58(as_text))34 self.assertTrue(encoding.is_hashed_base58_valid(as_text))35 bogus_text = as_text[:-1] + chr(1+ord(as_text[-1]))36 self.assertFalse(encoding.is_hashed_base58_valid(bogus_text))37 do_test("14nr3dMd4VwNpFhFECU1A6imi", b'\x00\x01\x93\\|\xf2*\xb9\xbe\x19b\xae\xe4\x8c{')38 do_test("1CASrvcpMMTa4dz4DmYtAqcegCtdkhjvdn", b'\x00zr\xb6\xfac\xde6\xc4\xab\xc6\nh\xb5-\x7f3\xe3\xd7\xcd>')39 do_test("11111111111111114njGbaozZJui9o",40 b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00CnzQ)\x0b')41 do_test("1mLRia5CbfDB9752zxvtrpnkigecaYWUSQNLJGECA8641ywusqomjhfdb6EM7bXGj1Gb",42 b'\x00\x01\x11\xd3\x8e_\xc9\x07\x1f\xfc\xd2\x0bJv<\xc9\xaeO%+\xb4\xe4\x8f\xd6j\x83^%*\xda\x93\xffH\rm\xd4=\xc6*d\x11U\xa5aaaa')43 def test_double_sha256(self):44 def do_test(blob, expected_hash):45 self.assertEqual(encoding.double_sha256(blob), expected_hash)46 do_test(b"This is a test",47 b'\xea\xc6I\xd41\xaa?\xc2\xd5t\x9d\x1aP!\xbb\xa7\x81.\xc8;\x8aY\xfa\x84\x0b\xffu\xc1\x7f\x8af\\')48 do_test(b"The quick brown fox jumps over the lazy dogs",49 b'\x8a5e\x88yz\x90\x1a\x11\x03\x17y\xd4xz\xd0E~\xb0\x82\xc5k\xd9\xb6W\x15z\xcf1\xba\xe6\xc4')50 do_test(b'\x74' * 10000,51 b'nMw6\xaa7<G\x18\xee\xf2\xb9E(\xfe\xd5u\x19\xa0\xbd\xc3\xa8\xf40\n\xee7,\xbe\xde\xa9\xa0')52 def test_hash160(self):53 def do_test(blob, expected_hash):54 self.assertEqual(encoding.hash160(blob), expected_hash)55 do_test(b"This is a test",56 b'\x18\xac\x98\xfa*$\x12\xdd\xb7]\xe6\x04Y\xb5*\xcd\x98\xf2\xd9r')57 do_test(b"The quick brown fox jumps over the lazy dogs",58 b'v\xc9\xd1\xf3\xaaR&UN G_\x91\x9a\xad\xd1t\xf7\xe9\xb7')59 do_test(b'\x74' * 10000,60 b'\xa9a\x07\x02\x96gt\x01\xa5~\xae\r\x96\xd1MZ\x88\n,A')61 def test_wif_to_from_secret_exponent(self):62 def do_test(as_secret_exponent, as_wif, is_compressed):63 self.assertEqual(as_wif, encoding.secret_exponent_to_wif(as_secret_exponent, compressed=is_compressed))64 se, comp = encoding.wif_to_tuple_of_secret_exponent_compressed(as_wif)65 self.assertEqual(se, as_secret_exponent)66 self.assertEqual(comp, is_compressed)67 self.assertTrue(encoding.is_valid_wif(as_wif))68 WIF_LIST = [69 "5HwoXVkHoRM8sL2KmNRS217n1g8mPPBomrY7yehCuXC1115WWsh",70 "5J5KUK3VXP8HUefNVYPxwxVRokScZdWXpu1Tj8LfaAXMqHzMmbk",71 "5JCqR8LhFLuS5yJRDiNVsus5bpkTjsqFswUoUbz8EorifYA4TwJ",72 "5JLMMwdtyJgahHwTwtM2osEjPu4Jv89yvyx9E5dauTC5Vs6EjBA",73 "5JTsJkw6hGTjJcaWg4KZjpcPByNA6NUhz2RUyZH3a6XSL7vAYmy",74 "5JbPFaEJREEsuwDZQEJ6fmz2z3g1GcoS34tpj2vWEjroARtCMBF",75 "5JiuCPXW9C22XFrc8QGdbjMgn7yrSs8A67NAUWZxuPC9ziUizQP",76 "5JrR9Cphs9oB8aVeraFAXgjLaCHhd7St99qWDzDRa2XWq3RVw7d",77 "5Jyw627ub7aKju8hakDhTe6zNGbYoMmcCCJqyTrtEfrsfLDreVt",78 "5K7T2qR7K5MUMDmkJvCEPbUeALuPyc6LFEnBiwWLuKCEVdBp8qV",79 "5KExyeiK338cxYQo36AmKYrHxRDF9rR4JHFXUR9oZxXbKue7gdL",80 "5KNUvU1WkzumZs3qmG9JFWDwkVX6L6jnMKisDtoGEbrxACzxk6T",81 "5KVzsHJiUxgvBBgtVS7qBTbbYZpwWM4WQNCCyNSiuFCJzYMxg8H",82 "5KdWp6bvCvU4nWKwDc6N7QyFLe8ngbPETQfYir6BZtXfpsnSrGS",83 ]84 SE_LIST = [int(c * 64, 16) for c in "123456789abcde"]85 for se, wif in zip(SE_LIST, WIF_LIST):86 do_test(se, wif, is_compressed=False)87 def test_public_pair_to_sec(self):88 def do_test(as_public_pair, as_sec, is_compressed, as_hash160_sec, as_bitcoin_address):89 self.assertEqual(encoding.sec_to_public_pair(as_sec), as_public_pair)90 self.assertEqual(encoding.public_pair_to_sec(as_public_pair, compressed=is_compressed), as_sec)91 self.assertEqual(encoding.is_sec_compressed(as_sec), is_compressed)92 self.assertEqual(encoding.public_pair_to_hash160_sec(as_public_pair, compressed=is_compressed),93 as_hash160_sec)94 self.assertEqual(encoding.hash160_sec_to_bitcoin_address(as_hash160_sec), as_bitcoin_address)95 self.assertEqual(encoding.public_pair_to_bitcoin_address(as_public_pair, compressed=is_compressed), as_bitcoin_address)96 self.assertTrue(encoding.is_valid_bitcoin_address(as_bitcoin_address))97 bad_address = as_bitcoin_address[:17] + chr(ord(as_bitcoin_address[17]) + 1) + as_bitcoin_address[18:]98 self.assertFalse(encoding.is_valid_bitcoin_address(bad_address))99 SEC_TEST_DATA = [100 ((35826991941973211494003564265461426073026284918572421206325859877044495085994,101 25491041833361137486709012056693088297620945779048998614056404517283089805761),102 "034f355bdcb7cc0af728ef3cceb9615d90684bb5b2ca5f859ab0f0b704075871aa",103 True,104 "fc7250a211deddc70ee5a2738de5f07817351cef",105 "1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nK9"106 ),107 ((31855367722742370537280679280108010854876607759940877706949385967087672770343,108 46659058944867745027460438812818578793297503278458148978085384795486842595210),109 "02466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f27",110 True,111 "531260aa2a199e228c537dfa42c82bea2c7c1f4d",112 "18aF6pYXKDSXjXHpidt2G6okdVdBr8zA7z"113 ),114 ((27341391395138457474971175971081207666803680341783085051101294443585438462385,115 26772005640425216814694594224987412261034377630410179754457174380653265224672),116 "023c72addb4fdf09af94f0c94d7fe92a386a7e70cf8a1d85916386bb2535c7b1b1",117 True,118 "3bc28d6d92d9073fb5e3adf481795eaf446bceed",119 "16Syw4SugWs4siKbK8cuxJXM2ukh2GKpRi"120 ),121 ((35826991941973211494003564265461426073026284918572421206325859877044495085994,122 25491041833361137486709012056693088297620945779048998614056404517283089805761),123 "044f355bdcb7cc0af728ef3cceb9615d90684bb5b2ca5f859ab0f0b704075871aa"\124 "385b6b1b8ead809ca67454d9683fcf2ba03456d6fe2c4abe2b07f0fbdbb2f1c1",125 False,126 "e4e517ee07984a4000cd7b00cbcb545911c541c4",127 "1MsHWS1BnwMc3tLE8G35UXsS58fKipzB7a"128 ),129 ((31855367722742370537280679280108010854876607759940877706949385967087672770343,130 46659058944867745027460438812818578793297503278458148978085384795486842595210),131 "04466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f27"\132 "6728176c3c6431f8eeda4538dc37c865e2784f3a9e77d044f33e407797e1278a",133 False,134 "b256082b934fe782adbacaafeadfca64c52a5384",135 "1HFxLkPTtMZeo5mDpZn6CF9sh4h2ycknwr"136 ),137 ((27341391395138457474971175971081207666803680341783085051101294443585438462385,138 26772005640425216814694594224987412261034377630410179754457174380653265224672),139 "043c72addb4fdf09af94f0c94d7fe92a386a7e70cf8a1d85916386bb2535c7b1b1"\140 "3b306b0fe085665d8fc1b28ae1676cd3ad6e08eaeda225fe38d0da4de55703e0",141 False,142 "edf6bbd7ba7aad222c2b28e6d8d5001178e3680c",143 "1NhEipumt9Pug6pwTqMNRXhBG84K39Ebbi"144 ),145 ]146 for public_pair, sec, compressed, hash160_sec, bitcoin_address in SEC_TEST_DATA:147 do_test(public_pair, h2b(sec), compressed, h2b(hash160_sec), bitcoin_address)148if __name__ == '__main__':...
01-connect-zero-length-id.py
Source:01-connect-zero-length-id.py
...13 f.write("listener %d\n" % (port1))14 f.write("allow_anonymous true\n")15 if allow_zero != "":16 f.write("allow_zero_length_clientid %s\n" % (allow_zero))17def do_test(per_listener, proto_ver, clean_start, allow_zero, client_port, expect_fail):18 conf_file = os.path.basename(__file__).replace('.py', '.conf')19 write_config(conf_file, port1, port2, per_listener, allow_zero)20 rc = 121 keepalive = 1022 connect_packet = mosq_test.gen_connect("", keepalive=keepalive, proto_ver=proto_ver, clean_session=clean_start)23 if proto_ver == 4:24 if expect_fail == True:25 connack_packet = mosq_test.gen_connack(rc=2, proto_ver=proto_ver)26 else:27 connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)28 else:29 if expect_fail == True:30 connack_packet = mosq_test.gen_connack(rc=128, proto_ver=proto_ver, properties=None)31 else:32 props = mqtt5_props.gen_string_prop(mqtt5_props.PROP_ASSIGNED_CLIENT_IDENTIFIER, "auto-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")33 connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver, properties=props)34 # Remove the "xxxx" part - this means the front part of the packet35 # is correct (so remaining length etc. is correct), but we don't36 # need to match against the random id.37 connack_packet = connack_packet[:-39]38 broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port1, use_conf=True)39 try:40 sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=client_port)41 sock.close()42 rc = 043 except mosq_test.TestError:44 pass45 finally:46 broker.terminate()47 broker.wait()48 (stdo, stde) = broker.communicate()49 os.remove(conf_file)50 if rc:51 print(stde.decode('utf-8'))52 print("per_listener:%s proto_ver:%d client_port:%d clean_start:%d allow_zero:%s" % (per_listener, proto_ver, client_port, clean_start, allow_zero))53 print("port1:%d port2:%d" % (port1, port2))54 exit(rc)55(port1, port2) = mosq_test.get_port(2)56test_v4 = True57test_v5 = True58if test_v4 == True:59 do_test(per_listener="false", proto_ver=4, client_port=port1, clean_start=True, allow_zero="true", expect_fail=False)60 do_test(per_listener="false", proto_ver=4, client_port=port1, clean_start=True, allow_zero="false", expect_fail=True)61 do_test(per_listener="false", proto_ver=4, client_port=port1, clean_start=False, allow_zero="true", expect_fail=True)62 do_test(per_listener="false", proto_ver=4, client_port=port1, clean_start=False, allow_zero="false", expect_fail=True)63 do_test(per_listener="true", proto_ver=4, client_port=port1, clean_start=True, allow_zero="true", expect_fail=False)64 do_test(per_listener="true", proto_ver=4, client_port=port1, clean_start=True, allow_zero="false", expect_fail=True)65 do_test(per_listener="true", proto_ver=4, client_port=port1, clean_start=False, allow_zero="true", expect_fail=True)66 do_test(per_listener="true", proto_ver=4, client_port=port1, clean_start=False, allow_zero="false", expect_fail=True)67 do_test(per_listener="false", proto_ver=4, client_port=port2, clean_start=True, allow_zero="true", expect_fail=False)68 do_test(per_listener="false", proto_ver=4, client_port=port2, clean_start=True, allow_zero="false", expect_fail=True)69 do_test(per_listener="false", proto_ver=4, client_port=port2, clean_start=False, allow_zero="true", expect_fail=True)70 do_test(per_listener="false", proto_ver=4, client_port=port2, clean_start=False, allow_zero="false", expect_fail=True)71 do_test(per_listener="true", proto_ver=4, client_port=port2, clean_start=True, allow_zero="true", expect_fail=False)72 do_test(per_listener="true", proto_ver=4, client_port=port2, clean_start=True, allow_zero="false", expect_fail=True)73 do_test(per_listener="true", proto_ver=4, client_port=port2, clean_start=False, allow_zero="true", expect_fail=True)74 do_test(per_listener="true", proto_ver=4, client_port=port2, clean_start=False, allow_zero="false", expect_fail=True)75 do_test(per_listener="false", proto_ver=4, client_port=port1, clean_start=True, allow_zero="", expect_fail=False)76 do_test(per_listener="false", proto_ver=4, client_port=port1, clean_start=False, allow_zero="", expect_fail=True)77 do_test(per_listener="true", proto_ver=4, client_port=port1, clean_start=True, allow_zero="", expect_fail=False)78 do_test(per_listener="true", proto_ver=4, client_port=port1, clean_start=False, allow_zero="", expect_fail=True)79 do_test(per_listener="false", proto_ver=4, client_port=port2, clean_start=True, allow_zero="", expect_fail=False)80 do_test(per_listener="false", proto_ver=4, client_port=port2, clean_start=False, allow_zero="", expect_fail=True)81 do_test(per_listener="true", proto_ver=4, client_port=port2, clean_start=True, allow_zero="", expect_fail=False)82 do_test(per_listener="true", proto_ver=4, client_port=port2, clean_start=False, allow_zero="", expect_fail=True)83if test_v5 == True:84 do_test(per_listener="false", proto_ver=5, client_port=port1, clean_start=True, allow_zero="true", expect_fail=False)85 do_test(per_listener="false", proto_ver=5, client_port=port1, clean_start=True, allow_zero="false", expect_fail=True)86 do_test(per_listener="false", proto_ver=5, client_port=port1, clean_start=False, allow_zero="true", expect_fail=False)87 do_test(per_listener="false", proto_ver=5, client_port=port1, clean_start=False, allow_zero="false", expect_fail=True)88 do_test(per_listener="true", proto_ver=5, client_port=port1, clean_start=True, allow_zero="true", expect_fail=False)89 do_test(per_listener="true", proto_ver=5, client_port=port1, clean_start=True, allow_zero="false", expect_fail=True)90 do_test(per_listener="true", proto_ver=5, client_port=port1, clean_start=False, allow_zero="true", expect_fail=False)91 do_test(per_listener="true", proto_ver=5, client_port=port1, clean_start=False, allow_zero="false", expect_fail=True)92 do_test(per_listener="false", proto_ver=5, client_port=port2, clean_start=True, allow_zero="true", expect_fail=False)93 do_test(per_listener="false", proto_ver=5, client_port=port2, clean_start=True, allow_zero="false", expect_fail=True)94 do_test(per_listener="false", proto_ver=5, client_port=port2, clean_start=False, allow_zero="true", expect_fail=False)95 do_test(per_listener="false", proto_ver=5, client_port=port2, clean_start=False, allow_zero="false", expect_fail=True)96 do_test(per_listener="true", proto_ver=5, client_port=port2, clean_start=True, allow_zero="true", expect_fail=False)97 do_test(per_listener="true", proto_ver=5, client_port=port2, clean_start=True, allow_zero="false", expect_fail=True)98 do_test(per_listener="true", proto_ver=5, client_port=port2, clean_start=False, allow_zero="true", expect_fail=False)99 do_test(per_listener="true", proto_ver=5, client_port=port2, clean_start=False, allow_zero="false", expect_fail=True)100 do_test(per_listener="false", proto_ver=5, client_port=port1, clean_start=True, allow_zero="", expect_fail=False)101 do_test(per_listener="false", proto_ver=5, client_port=port1, clean_start=False, allow_zero="", expect_fail=False)102 do_test(per_listener="true", proto_ver=5, client_port=port1, clean_start=True, allow_zero="", expect_fail=False)103 do_test(per_listener="true", proto_ver=5, client_port=port1, clean_start=False, allow_zero="", expect_fail=False)104 do_test(per_listener="false", proto_ver=5, client_port=port2, clean_start=True, allow_zero="", expect_fail=False)105 do_test(per_listener="false", proto_ver=5, client_port=port2, clean_start=False, allow_zero="", expect_fail=False)106 do_test(per_listener="true", proto_ver=5, client_port=port2, clean_start=True, allow_zero="", expect_fail=False)107 do_test(per_listener="true", proto_ver=5, client_port=port2, clean_start=False, allow_zero="", expect_fail=False)...
text.inline.js
Source:text.inline.js
...10 this._note.push(str);11 return '.' + this._note.length;12 }13}14function do_test(inline, test_case, parser) {15 for (let t of test_case) {16 let rv = inline(t[0]);17 test(`${t[0]} â ${t[1]}`, ()=>assert.equal(rv, t[1]));18 if (! t[2]) continue;19 let fn = parser._note[parser._note.length - 1];20 test(`${t[0]} â ${fn}`, ()=>assert.equal(fn, t[2]));21 }22}23suite('text/inline', ()=>{24suite('inline()', ()=>{25 const inline = require('../lib/text/inline')();26 test('require', ()=>assert.ok(inline));27 test('undefined â \'\'', ()=>assert.equal(inline(), ''));28 suite('markup', ()=>{29 suite('module', ()=>{30 const test_case = [31 [ '&_(tag param="1"){value};','<tag param="1">value</tag>' ],32 [ '&_(tag param="1"){};', '<tag param="1"></tag>' ],33 [ '&_(tag param="1");', '<tag param="1">' ],34 [ '&_(tag);', '<tag>' ],35 [ '&_(tag param="1" param);', '<tag param="1" param>' ],36 [ '&_(tag param=">");', '&_(tag param=">");' ],37 [ '&tag;', '&tag;' ],38 [ '&tag();', '&tag();' ],39 [ '&_(tag){}};', '<tag>}</tag>' ],40 [ '&_(tag1){&_(tag2){}};};' , '<tag1><tag2>}</tag2></tag1>' ],41 ];42 do_test(inline, test_case);43 });44 suite('strong', ()=>{45 const test_case = [46 [ '**&strong**', '<strong>&strong</strong>' ],47 [ '**\'\'strong\'\'**', '<strong><em>strong</em></strong>' ],48 ];49 do_test(inline, test_case);50 });51 suite('em', ()=>{52 const test_case = [53 [ '\'\'&em\'\'', '<em>&em</em>' ],54 [ '\'\'%%em%%\'\'', '<em><del>em</del></em>' ],55 ];56 do_test(inline, test_case);57 });58 suite('del', ()=>{59 const test_case = [60 [ '%%&del%%', '<del>&del</del>' ],61 [ '%%``em``%%', '<del><code>em</code></del>' ],62 ];63 do_test(inline, test_case);64 });65 suite('code', ()=>{66 const test_case = [67 [ '``&code``', '<code>&code</code>' ],68 [ '``**code**``', '<code><strong>code</strong></code>' ],69 ];70 });71 suite('kbd', ()=>{72 const test_case = [73 [ '```&kbd```', '<kbd>&kbd</kbd>' ],74 [ '```**kbd**```', '<kbd><strong>kbd</strong></kbd>' ],75 ];76 do_test(inline, test_case);77 });78 suite('as-is', ()=>{79 const test_case = [80 [ '{{&as-is}}', '&as-is' ],81 [ '{{%%as-is%%}}', '%%as-is%%' ],82 [ '{{Ӓ}}', '&#1234;' ],83 ];84 do_test(inline, test_case);85 });86 suite('bracket', ()=>{87 const test_case = [88 [ '[[&bracket]]', '<a href="&bracket">&bracket</a>' ],89 [ '[[A & B]]', '<a href="A%20&%20B">A & B</a>' ],90 [ '[[[bracket]]]', '[<a href="bracket">bracket</a>]' ],91 [ '[[bracket|./]]', '<a href="./">bracket</a>' ],92 [ '[[|bracket||./]]', '<a href="./">|bracket|</a>' ],93 [ '[[``bracket``]]', '<a href="%60%60bracket%60%60">``bracket``</a>'],94 [ '[[``bracket``|./]]', '<a href="./"><code>bracket</code></a>' ],95 [ '[[Home|/]]', '<a href="/">Home</a>' ],96 [ '[[ãã¹ã]]', '<a href="%E3%83%86%E3%82%B9%E3%83%88">ãã¹ã</a>' ],97 [ '[[100%|100%]]', '<a href="100%25">100%</a>' ],98 ];99 do_test(inline, test_case);100 });101 suite('footnote', ()=>{102 const test_case = [103 [ '((&footnote))', '(&footnote)' ],104 [ '(([[note]]))', '(<a href="note">note</a>)' ],105 ];106 do_test(inline, test_case);107 });108 });109 suite('text', ()=>{110 suite('link', ()=>{111 const test_case = [112 [ 'http://kobalab.net/',113 '<a href="http://kobalab.net/">http://kobalab.net/</a>' ],114 [ 'mailto:koba@kobalab.net',115 '<a href="mailto:koba@kobalab.net">mailto:koba@kobalab.net</a>' ],116 [ 'koba@kobalab.net',117 '<a href="mailto:koba@kobalab.net">koba@kobalab.net</a>' ],118 [ 'http://kobalab.net/?a=1&b=2',119 '<a href="http://kobalab.net/?a=1&b=2">'120 + 'http://kobalab.net/?a=1&b=2</a>' ],121 [ '<koba@kobalab.net>',122 '<<a href="mailto:koba@kobalab.net">koba@kobalab.net</a>>' ],123 ];124 do_test(inline, test_case);125 });126 });127});128suite('inline(parser)', ()=>{129 const inline = require('../lib/text/inline')(parser);130 test('require', ()=>assert.ok(inline));131 suite('module', ()=>{132 const test_case = [133 [ '&name(param){value};', '&name(param){value};' ],134 [ '&name;', '&name;' ],135 ];136 do_test(inline, test_case, parser);137 });138 suite('noteref', ()=>{139 const test_case = [140 [ '((¬eref))',141 '<sup class="l-footnote"><a id="l-noteref.1" href="#l-footnote.1" '142 + 'title="&noteref">*1</a></sup>',143 '&noteref' ],144 [ '(([[¬e]]))',145 '<sup class="l-footnote"><a id="l-noteref.2" href="#l-footnote.2" '146 + 'title="&note">*2</a></sup>',147 '<a href="&note">&note</a>' ],148 ];149 do_test(inline, test_case, parser);150 });151 suite('bracket', ()=>{152 const test_case = [153 [ '[[Home|/]]', '<a href="/base/">Home</a>' ],154 ];155 do_test(inline, test_case);156 });157});...
run_tests.py
Source:run_tests.py
...5from argparse import ArgumentParser6import re7import unittest8import os9def do_test(port, baudrate, test_name):10 databits = serial.EIGHTBITS11 stopbits = serial.STOPBITS_ONE12 parity = serial.PARITY_NONE13 ser = serial.Serial(port, baudrate, databits, parity, stopbits, timeout=10)14 ser.write('\n')15 finished = 016 success = False17 timeout = 10 # 10 seconds18 timeout_start = time.time()19 while True:20 serial_line = ser.readline()21 print(serial_line.replace('\n',''))22 if "nsh>" in serial_line:23 break24 elif "NuttShell (NSH)" in serial_line:25 break26 if time.time() > timeout_start + timeout:27 print("Error, timeout")28 break29 ser.write('\n')30 time.sleep(0.01)31 # run test cmd32 cmd = 'tests ' + test_name33 ser.write(cmd + '\n')34 timeout = 180 # 3 minutes35 timeout_start = time.time()36 timeout_newline = timeout_start37 while True:38 serial_line = ser.readline()39 print(serial_line.replace('\n',''))40 if cmd in serial_line:41 continue42 elif test_name + " PASSED" in serial_line:43 success = True44 break45 elif test_name + " FAILED" in serial_line:46 success = False47 break48 elif "nsh>" in serial_line:49 success = False50 break51 elif "NuttShell (NSH)" in serial_line:52 success = False53 break54 if time.time() > timeout_start + timeout:55 print("Error, timeout")56 print(test_name + " FAILED")57 success = False58 break59 # newline every 30 seconds if still running60 if time.time() - timeout_newline > 30:61 ser.write('\n')62 timeout_newline = time.time()63 ser.close()64 return success65class TestHadrwareMethods(unittest.TestCase):66 TEST_DEVICE = 067 TEST_BAUDRATE = 068 def test_bezier(self):69 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "bezier"))70 def test_bson(self):71 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "bson"))72 def test_commander(self):73 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "commander"))74 def test_controllib(self):75 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "controllib"))76# def test_dataman(self):77# self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "dataman"))78 def floattest_float(self):79 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "float"))80 def test_hrt(self):81 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "hrt"))82 def test_IntrusiveQueue(self):83 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "IntrusiveQueue"))84 def test_List(self):85 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "List"))86 def test_mathlib(self):87 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "mathlib"))88 def test_matrix(self):89 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "matrix"))90 def test_microbench_atomic(self):91 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "microbench_atomic"))92 def test_microbench_hrt(self):93 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "microbench_hrt"))94 def test_microbench_math(self):95 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "microbench_math"))96 def test_microbench_matrix(self):97 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "microbench_matrix"))98 def test_microbench_uorb(self):99 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "microbench_uorb"))100# def test_mixer(self):101# self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "mixer"))102 def test_param(self):103 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "param"))104 def test_parameters(self):105 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "parameters"))106 def test_perf(self):107 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "perf"))108 def search_mintest_xxx(self):109 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "search_min"))110 def test_sleep(self):111 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "sleep"))112 def test_smoothz(self):113 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "smoothz"))114 def test_time(self):115 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "time"))116 #def test_uorb(self):117 # self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "uorb"))118 def test_versioning(self):119 self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "versioning"))120def main():121 parser = ArgumentParser(description=__doc__)122 parser.add_argument('--device', "-d", nargs='?', default = None, help='')123 parser.add_argument("--baudrate", "-b", dest="baudrate", type=int, help="Mavlink port baud rate (default=57600)", default=57600)124 args = parser.parse_args()125 TestHadrwareMethods.TEST_DEVICE = args.device126 TestHadrwareMethods.TEST_BAUDRATE = args.baudrate127 unittest.main(__name__, argv=['main'])128if __name__ == "__main__":...
match.js
Source:match.js
...36 root_head.appendChild(tpl_td.cloneNode(true));37}38const headers = root_head.getElementsByTagName("td");39// -----------------------------------------------------------40await do_test("test-1", "without breach of modesty", [2684]);41await do_test("test-2", "went softly stream", [2432]);42await do_test("test-3", "princes of the ambition", [2259, 396]);43await do_test("test-4", "five-thousand leagues", [7]);44await do_test("test-5", "raise up soft", [2069]);45await do_test("test-6", "disgust the bigness", [946]);46await do_test("test-7", "bignes of splaknuk", [781]);47await do_test("test-8", "matematikal musikal instruments", [1480]);48await do_test("test-9", "composition of minerals gums juices vegetables", [1676, 2337]);49await do_test("test-10", "general camberlayhn", [520]);50await do_test("test-11", "the end defeat", [2209]);51await do_test("test-12", "fast chief", [1275]);52// ---------------------------------------53async function do_test(id, query, ref){54 const nodes = document.getElementById(id).getElementsByTagName("td");55 nodes[0].firstChild.nodeValue = query;56 for(let i = 0, current; i < lib.length; i++){57 current = lib[i].replace("-0.7.0", "").replace("-match", "");58 headers[i + 1].firstChild.nodeValue = current;59 const node = nodes[i + 1];60 const style = node.style;61 node.firstChild.nodeValue = "run ...";62 let results = await new Promise(function(resolve){63 promise = resolve;64 iframe.src = "test/" + lib[i] + "/?query=" + decodeURI(query) + (encode ? "&encode=true" : "") + "#match";65 });66 if(results.length){67 switch(current){...
send-data-es-object.any.js
Source:send-data-es-object.any.js
1// META: title=XMLHttpRequest.send(ES object)2function do_test(obj, expected, name) {3 var test = async_test(name)4 test.step(function() {5 var client = new XMLHttpRequest()6 client.onload = test.step_func(function () {7 assert_equals(client.responseText, expected)8 test.done()9 });10 client.open('POST', 'resources/content.py')11 if (expected.exception) {12 if (expected.exception.identity) {13 assert_throws_exactly(expected.exception.identity,14 function(){client.send(obj)})15 } else {16 assert_throws_js(expected.exception.ctor,17 function(){client.send(obj)})18 }19 test.done()20 } else {21 client.send(obj)22 }23 });24}25do_test({}, '[object Object]', 'sending a plain empty object')26do_test(Math, '[object Math]', 'sending the ES Math object')27do_test(new XMLHttpRequest, '[object XMLHttpRequest]', 'sending a new XHR instance')28do_test(new ReadableStream, '[object ReadableStream]', 'sending a new ReadableStream instance')29do_test({toString:function(){}}, 'undefined', 'sending object that stringifies to undefined')30do_test({toString:function(){return null}}, 'null', 'sending object that stringifies to null')31var ancestor = {toString: function(){32 var ar=[]33 for (var prop in this) {34 if (this.hasOwnProperty(prop)) {35 ar.push(prop+'='+this[prop])36 }37 };38 return ar.join('&')39}};40var myObj = Object.create(ancestor, {foo:{value:1, enumerable: true}, bar:{value:'foo', enumerable:true}})41do_test(myObj, 'foo=1&bar=foo', 'object that stringifies to query string')42var myFakeJSON = {a:'a', b:'b', toString:function(){ return JSON.stringify(this, function(key, val){ return key ==='toString'?undefined:val; }) }}43do_test(myFakeJSON, '{"a":"a","b":"b"}', 'object that stringifies to JSON string')44var myFakeDoc1 = {valueOf:function(){return document}}45do_test(myFakeDoc1, '[object Object]', 'object whose valueOf() returns a document - ignore valueOf(), stringify')46var myFakeDoc2 = {toString:function(){return document}}47var expectedError = self.GLOBAL.isWorker() ? ReferenceError : TypeError;48do_test(myFakeDoc2, {exception: { ctor: expectedError } }, 'object whose toString() returns a document, expected to throw')49var err = {name:'FooError', message:'bar'};50var myThrower = {toString:function(){throw err;}};...
test_flake8.py
Source:test_flake8.py
1import re2import subprocess3import unittest4class TestFlake8(unittest.TestCase):5 def do_test(self, filename: str):6 with open(filename, 'r') as f:7 lines = f.readlines()8 expectations = []9 for i, line in enumerate(lines):10 match = re.search(r'# *([A-Z]+[0-9]+ *,* *)*\n', line)11 if match:12 for expectation in re.split(r'\W+', match.group()[1:].strip()):13 expectations.append((i + 1, expectation))14 result = subprocess.run(15 ['flake8', filename],16 stdout=subprocess.PIPE,17 stderr=subprocess.PIPE)18 stdout_lines = result.stdout.splitlines()19 self.assertEqual(result.stderr, b'', 'STDERR is not empty.')20 self.assertEqual(len(stdout_lines), len(expectations),21 'Mismatch in number of outputs.')22 for i, (num, expectation) in enumerate(expectations):23 self.assertRegex(24 stdout_lines[i],25 f'{filename}:{num}:[0-9]+: {expectation}'.encode())26 def test_flake8_builtins(self):27 self.do_test('./test/example_flake8-builtins.py')28 def test_flake8_comprehensions(self):29 self.do_test('./test/example_flake8-comprehensions.py')30 def test_flake8_import_order(self):31 self.do_test('./test/example_flake8-import-order.py')32 def test_flake8_quotes(self):33 self.do_test('./test/example_flake8-quotes.py')34 def test_flake8_use_fstring(self):35 self.do_test('./test/example_flake8-use-fstring.py')36 def test_pep8_naming(self):37 self.do_test('./test/example_pep8-naming.py')38if __name__ == '__main__':...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 console.log('Test submitted to WebPagetest for %s', data.data.testUrl);5 console.log('Test ID: %s', data.data.testId);6 wpt.getTestResults(data.data.testId, function(err, data) {7 if (err) return console.error(err);8 console.log('Test completed for %s', data.data.testUrl);9 console.log('First View: %s', data.data.average.firstView.loadTime);10 console.log('Repeat View: %s', data.data.average.repeatView.loadTime);11 });12});13var wpt = require('webpagetest');14var wpt = new WebPageTest('www.webpagetest.org');15 if (err) return console.error(err);16 console.log('Test submitted to WebPagetest for %s', data.data.testUrl);17 console.log('Test ID: %s', data.data.testId);18 wpt.getTestResults(data.data.testId, function(err, data) {19 if (err) return console.error(err);20 console.log('Test completed for %s', data.data.testUrl);21 console.log('First View: %s', data.data.average.firstView.loadTime);22 console.log('Repeat View: %s', data.data.average.repeatView.loadTime);23 });24});25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpagetest.org');27 if (err) return console.error(err);28 console.log('Test submitted to WebPagetest for %s', data.data.testUrl);29 console.log('Test ID: %s', data.data.testId);30 wpt.getTestResults(data.data.testId, function(err, data) {31 if (err) return console.error(err);32 console.log('Test completed for %s', data.data.testUrl
Using AI Code Generation
1do_test(function() {2 var request = new XMLHttpRequest();3 request.onreadystatechange = function (aEvt) {4 if (request.readyState == 4) {5 if(request.status == 200)6 do_test_finished();7 }8 };9 request.send(null);10});11do_test(function() {12 var request = new XMLHttpRequest();13 request.onreadystatechange = function (aEvt) {14 if (request.readyState == 4) {15 if(request.status == 200)16 do_test_finished("Test passed");17 }18 };19 request.send(null);20});
Using AI Code Generation
1do_test();2do_test_pending();3do_test_finished();4do_check_eq(1,2);5do_check_true(false);6 do_test();7 do_test_pending();8 do_test_finished();9 do_check_eq(1,2);10 do_check_true(false);11import wpt12wpt.do_test()13import wpt14wpt.do_test_pending()15wpt.do_test_finished()16import wpt17wpt.do_check_eq(1,2)18import wpt19wpt.do_check_true(false)20include "wpt.php";21do_test();22include "wpt.php";23do_test_pending();24do_test_finished();25include "wpt.php";26do_check_eq(1,2);27include "wpt.php";28do_check_true(false);29include "wpt.php";30do_test();31include "wpt.php";32do_test_pending();33do_test_finished();
Using AI Code Generation
1do_test( function() {2 var test = async_test("Test path");3 var xhr = new XMLHttpRequest();4 xhr.open('GET', url);5 xhr.onload = test.step_func(function(e) {6 assert_equals(xhr.response, 'Hello World', 'response should be Hello World');7 test.done();8 });9 xhr.send();10});
Using AI Code Generation
1do_test("test", function() {2});3do_test("test", function() {4 return new Promise(function(resolve, reject) {5 resolve();6 });7});8do_test("test", function(done) {9 done();10});11do_test("test", function(done) {12 done();13}, 1000);14do_test("test", function(done) {15 done();16}, 1000);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!