Skip to content

Commit 0768e9f

Browse files
committed
multi line
1 parent 20447c0 commit 0768e9f

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ val lis: List[String] = qw"You can save time from double-quotation hell"
1919
// => List("You", "can", "save", "time", "from", "double-quotation", "hell")
2020
```
2121

22+
You can express list via multi-line:
23+
24+
```scala
25+
val lis = qw"""
26+
a b
27+
c d
28+
e f
29+
"""
30+
// => List("a", "b", "c", "d", "e", "f")
31+
```
32+
2233
#### Advanced usage
2334

2435
You can embed `String` variable into notation:

src/main/scala/com/github/windymelt/qw/Syntax.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ object Syntax:
55
def qw(args: String*): List[String] =
66
val strings = sc.parts.iterator
77
val expressions = args.iterator
8-
var buf = collection.mutable.ListBuffer(strings.next().split(" ")*)
8+
var buf = collection.mutable.ListBuffer(strings.next().split("\\s")*)
99
while strings.hasNext do
1010
buf.append(expressions.next().toString)
11-
buf.append(strings.next().toString.split(" ")*)
11+
buf.append(strings.next().toString.split("\\s")*)
1212
buf.filterNot(_.isEmpty).toList

src/test/scala/com/github/windymelt/qw/SyntaxSuite.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package com.github.windymelt.qw
2+
23
// For more information on writing tests, see
34
// https://scalameta.org/munit/docs/getting-started.html
45
class SyntaxSuite extends munit.FunSuite {
@@ -25,4 +26,13 @@ class SyntaxSuite extends munit.FunSuite {
2526
val (x, y, z) = ("a", "b", "c")
2627
assertEquals(qw"$x$y$z", List("a", "b", "c"))
2728
}
29+
30+
test("multiple line can be converted into list") {
31+
val lis = qw"""
32+
a
33+
b c
34+
d e
35+
"""
36+
assertEquals(lis, List("a", "b", "c", "d", "e"))
37+
}
2838
}

0 commit comments

Comments
 (0)