mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 20:47:35 +03:00
Add ability to reorder playlist items
This commit is contained in:
parent
b597a34cb4
commit
331fa1d952
8 changed files with 158 additions and 34 deletions
|
@ -25,3 +25,16 @@ func StringInSlice(a string, list []string) bool {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func InsertString(array []string, value string, index int) []string {
|
||||
return append(array[:index], append([]string{value}, array[index:]...)...)
|
||||
}
|
||||
|
||||
func RemoveString(array []string, index int) []string {
|
||||
return append(array[:index], array[index+1:]...)
|
||||
}
|
||||
|
||||
func MoveString(array []string, srcIndex int, dstIndex int) []string {
|
||||
value := array[srcIndex]
|
||||
return InsertString(RemoveString(array, srcIndex), value, dstIndex)
|
||||
}
|
||||
|
|
|
@ -48,4 +48,16 @@ var _ = Describe("Strings", func() {
|
|||
Expect(StringInSlice("bbb", []string{"bbb", "aaa", "ccc"})).To(BeTrue())
|
||||
})
|
||||
})
|
||||
|
||||
Describe("MoveString", func() {
|
||||
It("moves item to end of slice", func() {
|
||||
Expect(MoveString([]string{"1", "2", "3"}, 0, 2)).To(ConsistOf("2", "3", "1"))
|
||||
})
|
||||
It("moves item to beginning of slice", func() {
|
||||
Expect(MoveString([]string{"1", "2", "3"}, 2, 0)).To(ConsistOf("3", "1", "2"))
|
||||
})
|
||||
It("keeps item in same position if srcIndex == dstIndex", func() {
|
||||
Expect(MoveString([]string{"1", "2", "3"}, 1, 1)).To(ConsistOf("1", "2", "3"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue