From 6c8504238ddbd96deea577df58c043b95cb1068d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 7 Dec 2015 02:34:28 +0000 Subject: tracklist: swap functionality This (from the point of the client) will atomically swap two tracks. This should allow easily implementing of a tracklist editor. --- test/test_tracklist.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test') diff --git a/test/test_tracklist.rb b/test/test_tracklist.rb index c918ff7..c05090c 100644 --- a/test/test_tracklist.rb +++ b/test/test_tracklist.rb @@ -120,4 +120,15 @@ class TestTracklist < Testcase assert_kind_of Integer, tl.add_track('y') assert_equal 2, tl.instance_variable_get(:@list).size end + + def test_swap + tl = DTAS::Tracklist.new + list_add(tl, %w(a b c d e f g)) + mapping = _build_mapping(tl) + assert tl.swap(mapping['a'], mapping['g']) + assert_equal %w(g b c d e f a), list_to_path(tl) + + assert_nil tl.swap(-2, -3), 'no swap on invalid' + assert_equal %w(g b c d e f a), list_to_path(tl) + end end -- cgit v1.2.3-24-ge0c7