fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes Altmanningertests: filter control sequences only when interactive1e858eae3

master
3.2 KiB122 linesraw
1#RUN: %fish %s
2# Tests for importing named regex groups as fish variables
3
4# Invalid variable name?
5string match --regex -q '(?<FISH_VERSION>.*)' -- derp
6# CHECKERR: Modification of read-only variable "FISH_VERSION" is not allowed
7
8# Capture first match
9echo "hello world" | string match --regex -q -- '(?<words>[^ ]+) ?'
10printf "%s\n" $words
11# CHECK: hello
12
13# Capture multiple matches
14echo "hello world" | string match --regex -q --all -- '(?<words>[^ ]+) ?'
15printf "%s\n" $words
16# CHECK: hello
17# CHECK: world
18
19# Capture multiple variables
20echo "hello world"\n"snello snorld" | string match -rq -- '^(?<word1>[^ ]+) (?<word2>.*)$'
21printf "%s\n" $word1 $word2
22# CHECK: hello
23# CHECK: world
24
25# Clear variables on no match
26set foo foo
27echo foo | string match -rq -- '^(?<foo>bar)$'
28echo $foo
29# CHECK:
30
31# Named group may be empty in some of the matches
32set word
33set punctuation
34echo "hello world, boy!" | string match -a -qr -- '(?<word>[^ .,!;]+)(?<punctuation>[.,!;])?'
35echo $word
36# CHECK: hello world boy
37printf "%s\n" $punctuation
38# CHECK:
39# CHECK: ,
40# CHECK: !
41
42# Same thing with multiple arguments
43set word
44set punctuation
45printf '%s\n' "hello world, boy!" "shello shorld, shoy!" | string match -a -qr -- '(?<word>[^ .,!;]+)(?<punctuation>[.,!;])?'
46echo $word
47# CHECK: hello world boy
48printf "%s\n" $punctuation
49# CHECK:
50# CHECK: ,
51# CHECK: !
52
53# Verify read-only variables may not be imported
54echo hello | string match -rq "(?<version>.*)"
55# CHECKERR: Modification of read-only variable "version" is not allowed
56
57# Verify that the *first matching argument* is used.
58string match -rq '(?<bee>b.*)' -- aaa ba ccc be
59echo $bee
60# CHECK: ba
61
62# Verify the following regarding capture groups which are not matched:
63#    1. Set no values if --all is not provided
64#    2. Set an empty string value if --all is provided
65set -e nums
66set -e text
67
68string match -r '(?<nums>\d+)|(?<text>[a-z]+)' -- xyz
69# CHECK: xyz
70# CHECK: xyz
71set --show text
72# CHECK: $text: set in global scope, unexported, with 1 elements
73# CHECK: $text[1]: |xyz|
74set --show nums
75# CHECK: $nums: set in global scope, unexported, with 0 elements
76
77string match -r --all '(?<nums>\d+)|(?<text>[a-z]+)' -- '111 aaa 222 bbb'
78# CHECK: 111
79# CHECK: 111
80# CHECK: aaa
81# CHECK: aaa
82# CHECK: 222
83# CHECK: 222
84# CHECK: bbb
85# CHECK: bbb
86
87set --show nums
88# CHECK: $nums: set in global scope, unexported, with 4 elements
89# CHECK: $nums[1]: |111|
90# CHECK: $nums[2]: ||
91# CHECK: $nums[3]: |222|
92# CHECK: $nums[4]: ||
93
94set --show text
95# CHECK: $text: set in global scope, unexported, with 4 elements
96# CHECK: $text[1]: ||
97# CHECK: $text[2]: |aaa|
98# CHECK: $text[3]: ||
99# CHECK: $text[4]: |bbb|
100
101# Regression test for #7938.
102set -e text
103echo one\ntwo | string match -ra '(?<text>[a-z]+)'
104# CHECK: one
105# CHECK: one
106# CHECK: two
107# CHECK: two
108set --show text
109# CHECK: $text: set in global scope, unexported, with 1 elements
110# CHECK: $text[1]: |one|
111
112set -e text
113echo three\nfour | string match -qra '(?<text>[a-z]+)'
114set --show text
115# CHECK: $text: set in global scope, unexported, with 1 elements
116# CHECK: $text[1]: |three|
117
118set -e text
119echo 555\nsix | string match -qra '(?<text>[a-z]+)'
120set --show text
121# CHECK: $text: set in global scope, unexported, with 1 elements
122# CHECK: $text[1]: |six|