1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
 
START_MARKER 
 
test_do( add_constant("id",lambda(string x) { x=x+" "*(20-sizeof(x)); return Protocols.Bittorrent.PeerID.identify_peer(x); }) ) 
 
test_eq( id(""), "unknown" ) 
test_eq( id("-AZ2060-"), "Azureus 2.0.6.0" ) 
test_eq( id("-AR1234-"), "Arctic 1234" ) 
test_eq( id("S58B-----"), "Shadow 5.8.11" ) 
test_eq( id("M3-4-2--"), "Mainline 3.4.2" ) 
test_eq( id("M4-20-8-"), "Mainline 4.20.8" ) 
test_eq( id("XBT054d-"), "XBT 0.5.4 (debug)" ) 
test_eq( id("XBT054--"), "XBT 0.5.4" ) 
test_eq( id("OP800B"), "Opera 800B" ) 
test_eq( id("-ML2.7.2-kgjjfkd"), "MLdonkey 2.7.2" ) 
test_eq( id("-BOWA0C-"), "Bits on Wheels" ) 
test_eq( id("AZ2500BT"), "BitTyrant 1.1" ) 
test_eq( id("\0\3BS"), "BitSpirit 3" ) 
test_eq( id("10RS"), "Rufus 10" ) 
test_eq( id("-G3"), "G3 Torrent" ) 
test_eq( id("BLZ123"), "Blizzard 123") 
test_eq( id("\0"*20), "Experimental 3.1" ) 
 
test_do( add_constant("id") ) 
 
test_do( add_constant("d", Protocols.Bittorrent.Bencoding.decode) ) 
test_equal( d("4:spamx"), "spam" ) 
test_equal( d("4:spa"), 0 ) 
test_equal( d("i0ex"), 0 ) 
test_equal( d("i0"), 0 ) 
test_equal( d("i-3ex"), -3 ) 
test_equal( d("i1234567890ex"), 1234567890 ) 
test_equal( d("l4:spam4:eggsex"), ({ "spam", "eggs" }) ) 
test_equal( d("l4:spam4:eggs"), ({ "spam", "eggs" }) ) 
test_equal( d("d3:cow3:moo4:spam4:eggsex"), ([ "cow":"moo", "spam":"eggs" ]) ) 
test_equal( d("d3:cow3:moo4:spam4:eggs"), ([ "cow":"moo", "spam":"eggs" ]) ) 
test_equal( d("d4:spaml1:a1:bee"), ([ "spam" : ({ "a", "b" }) ]) ) 
test_eval_error( d("x") ) 
test_do( add_constant("d") ) 
 
 
END_MARKER