diff --git a/internal/stage_bencode_list.go b/internal/stage_bencode_list.go index 2c46391..de4da6c 100644 --- a/internal/stage_bencode_list.go +++ b/internal/stage_bencode_list.go @@ -81,5 +81,26 @@ func testBencodeList(stageHarness *tester_utils.StageHarness) error { return err } + // Test for a nested list: [[4], 5] + nestedListEncoded = "lli4eei5ee" + nestedList = []string{ + "[[4],5]\n", + "[[4], 5]\n", + } + logger.Infof("Running ./your_bittorrent.sh decode %s", nestedListEncoded) + logger.Infof("Expected output: %s", strings.TrimSpace(nestedList[0])) + result, err = executable.Run("decode", nestedListEncoded) + if err != nil { + return err + } + + if err = assertExitCode(result, 0); err != nil { + return err + } + + if err = assertStdoutList(result, nestedList); err != nil { + return err + } + return nil } diff --git a/internal/test_helpers/fixtures/handshake/with_peer_check b/internal/test_helpers/fixtures/handshake/with_peer_check index 368173e..ac1e5c0 100644 --- a/internal/test_helpers/fixtures/handshake/with_peer_check +++ b/internal/test_helpers/fixtures/handshake/with_peer_check @@ -26,6 +26,9 @@ Debug = true [stage-3] Running ./your_bittorrent.sh decode lli461e4:pearee [stage-3] Expected output: [[461,"pear"]] [your_program] [[461,"pear"]] +[stage-3] Running ./your_bittorrent.sh decode lli4eei5ee +[stage-3] Expected output: [[4],5] +[your_program] [[4],5] [stage-3] Test passed. [stage-4] Running tests for Stage #4: bencode-dict @@ -41,7 +44,7 @@ Debug = true [stage-4] Test passed. [stage-5] Running tests for Stage #5: parse-torrent -[stage-5] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2052448423/codercat.gif.torrent +[stage-5] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2207864171/codercat.gif.torrent [your_program] Tracker URL: http://bittorrent-test-tracker.codecrafters.io/announce [your_program] Length: 2994120 [your_program] Info Hash: c77829d2a77d6516f88cd7a3de1a26abcbfab0db @@ -66,7 +69,7 @@ Debug = true [stage-5] Test passed. [stage-6] Running tests for Stage #6: infohash -[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1703661002/itsworking.gif.torrent +[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents856298118/itsworking.gif.torrent [your_program] Tracker URL: http://bittorrent-test-tracker.codecrafters.io/announce [your_program] Length: 2549700 [your_program] Info Hash: 70edcac2611a8829ebf467a6849f5d8408d9d8f4 @@ -82,7 +85,7 @@ Debug = true [your_program] 272a8ff8fc865b053d974a78681414b38077d7b1 [your_program] b07128d3a6018062bfe779db96d3a93c05fb81d4 [your_program] 7affc94f0985b985eb888a36ec92652821a21be4 -[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1703661002/congratulations.gif.torrent +[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents856298118/congratulations.gif.torrent [your_program] Tracker URL: http://bittorrent-test-tracker.codecrafters.io/announce [your_program] Length: 820892 [your_program] Info Hash: 1cad4a486798d952614c394eb15e75bec587fd08 @@ -92,7 +95,7 @@ Debug = true [your_program] 69f885b3988a52ffb03591985402b6d5285940ab [your_program] 76869e6c9c1f101f94f39de153e468be6a638f4f [your_program] bded68d02de011a2b687f75b5833f46cce8e3e9c -[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1703661002/codercat.gif.torrent +[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents856298118/codercat.gif.torrent [your_program] Tracker URL: http://bittorrent-test-tracker.codecrafters.io/announce [your_program] Length: 2994120 [your_program] Info Hash: c77829d2a77d6516f88cd7a3de1a26abcbfab0db @@ -113,7 +116,7 @@ Debug = true [stage-6] Test passed. [stage-7] Running tests for Stage #7: hashes -[stage-7] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1607475511/test.torrent +[stage-7] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1460619742/test.torrent [your_program] Tracker URL: http://bttracker.debian.org:6969/announce [your_program] Length: 1835008 [your_program] Info Hash: 1840a71323682db707d1e8c9761049e875c03656 @@ -129,8 +132,8 @@ Debug = true [stage-7] Test passed. [stage-8] Running tests for Stage #8: peers -[stage-8] Running ./your_bittorrent.sh peers /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2494430895/test.torrent -[stage-8] Server started on port 127.0.0.1:51421... +[stage-8] Running ./your_bittorrent.sh peers /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1169253597/test.torrent +[stage-8] Server started on port 127.0.0.1:51530...  [your_program] 188.119.61.177:6881 [your_program] 71.224.0.29:51414 @@ -144,8 +147,8 @@ Debug = true [stage-8] Test passed. [stage-9] Running tests for Stage #9: handshake -[stage-9] Running ./your_bittorrent.sh handshake /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1326706543/test.torrent 127.0.0.1:51423 -[stage-9] Server started on port 127.0.0.1:51424... +[stage-9] Running ./your_bittorrent.sh handshake /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1324119407/test.torrent 127.0.0.1:51532 +[stage-9] Server started on port 127.0.0.1:51533...  [stage-9] Waiting for handshake message [stage-9] Received handshake: [infohash: c7e51462e85d8631c25f8c9b8c5479345a1de26b, peer_id: 3030313132323333343435353636373738383939] diff --git a/internal/test_helpers/fixtures/pass_all b/internal/test_helpers/fixtures/pass_all index 920eca2..975e821 100644 --- a/internal/test_helpers/fixtures/pass_all +++ b/internal/test_helpers/fixtures/pass_all @@ -24,6 +24,9 @@ [stage-3] Running ./your_bittorrent.sh decode lli461e4:pearee [stage-3] Expected output: [[461,"pear"]] [your_program] [[461,"pear"]] +[stage-3] Running ./your_bittorrent.sh decode lli4eei5ee +[stage-3] Expected output: [[4],5] +[your_program] [[4],5] [stage-3] Test passed. [stage-4] Running tests for Stage #4: bencode-dict @@ -39,7 +42,7 @@ [stage-4] Test passed. [stage-5] Running tests for Stage #5: parse-torrent -[stage-5] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents308331727/codercat.gif.torrent +[stage-5] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1616922747/codercat.gif.torrent [your_program] Tracker URL: http://bittorrent-test-tracker.codecrafters.io/announce [your_program] Length: 2994120 [your_program] Info Hash: c77829d2a77d6516f88cd7a3de1a26abcbfab0db @@ -62,7 +65,7 @@ [stage-5] Test passed. [stage-6] Running tests for Stage #6: infohash -[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2614696642/itsworking.gif.torrent +[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2551964154/itsworking.gif.torrent [your_program] Tracker URL: http://bittorrent-test-tracker.codecrafters.io/announce [your_program] Length: 2549700 [your_program] Info Hash: 70edcac2611a8829ebf467a6849f5d8408d9d8f4 @@ -78,7 +81,7 @@ [your_program] 272a8ff8fc865b053d974a78681414b38077d7b1 [your_program] b07128d3a6018062bfe779db96d3a93c05fb81d4 [your_program] 7affc94f0985b985eb888a36ec92652821a21be4 -[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2614696642/congratulations.gif.torrent +[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2551964154/congratulations.gif.torrent [your_program] Tracker URL: http://bittorrent-test-tracker.codecrafters.io/announce [your_program] Length: 820892 [your_program] Info Hash: 1cad4a486798d952614c394eb15e75bec587fd08 @@ -88,7 +91,7 @@ [your_program] 69f885b3988a52ffb03591985402b6d5285940ab [your_program] 76869e6c9c1f101f94f39de153e468be6a638f4f [your_program] bded68d02de011a2b687f75b5833f46cce8e3e9c -[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2614696642/codercat.gif.torrent +[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2551964154/codercat.gif.torrent [your_program] Tracker URL: http://bittorrent-test-tracker.codecrafters.io/announce [your_program] Length: 2994120 [your_program] Info Hash: c77829d2a77d6516f88cd7a3de1a26abcbfab0db @@ -109,7 +112,7 @@ [stage-6] Test passed. [stage-7] Running tests for Stage #7: hashes -[stage-7] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2451637776/test.torrent +[stage-7] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1322099590/test.torrent [your_program] Tracker URL: http://bttracker.debian.org:6969/announce [your_program] Length: 1835008 [your_program] Info Hash: 1840a71323682db707d1e8c9761049e875c03656 @@ -125,7 +128,7 @@ [stage-7] Test passed. [stage-8] Running tests for Stage #8: peers -[stage-8] Running ./your_bittorrent.sh peers /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents382743495/test.torrent +[stage-8] Running ./your_bittorrent.sh peers /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents712288102/test.torrent [your_program] 188.119.61.177:6881 [your_program] 71.224.0.29:51414 [your_program] 62.153.208.98:3652 @@ -138,15 +141,15 @@ [stage-8] Test passed. [stage-9] Running tests for Stage #9: handshake -[stage-9] Running ./your_bittorrent.sh handshake /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1302044088/test.torrent 127.0.0.1:51430 +[stage-9] Running ./your_bittorrent.sh handshake /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents660096687/test.torrent 127.0.0.1:51538 [your_program] Peer ID: ee8f5140bfc195c36b0567cd055ac9839e682ab0 [stage-9] Test passed. [stage-10] Running tests for Stage #10: dl-piece -[stage-10] Running ./your_bittorrent.sh download_piece -o /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents3765219977/piece-2 /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents3765219977/congratulations.gif.torrent 2 -[stage-10] Running ./your_bittorrent.sh download_piece -o /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents3765219977/piece-3 /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents3765219977/congratulations.gif.torrent 3 +[stage-10] Running ./your_bittorrent.sh download_piece -o /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents3503847342/piece-2 /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents3503847342/congratulations.gif.torrent 2 +[stage-10] Running ./your_bittorrent.sh download_piece -o /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents3503847342/piece-3 /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents3503847342/congratulations.gif.torrent 3 [stage-10] Test passed. [stage-11] Running tests for Stage #11: dl-file -[stage-11] Running ./your_bittorrent.sh download -o /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2788206242/codercat.gif /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2788206242/codercat.gif.torrent +[stage-11] Running ./your_bittorrent.sh download -o /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents4213953347/codercat.gif /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents4213953347/codercat.gif.torrent [stage-11] Test passed.