├── .gitattributes
├── .github
├── FUNDING.yml
└── workflows
│ └── test.yml
├── .gitmodules
├── Dockerfile
├── LICENSE
├── README.md
├── bin
├── addb.egi
├── addl.egi
├── addr.egi
├── addt.egi
├── comb.egi
├── conv.egi
├── crops.egi
├── cycle.egi
├── dropl.egi
├── dropr.egi
├── dupl.egi
├── flat.egi
├── mirror.egi
├── nestl.egi
├── nestr.egi
├── obrev.egi
├── perm.egi
├── slit.egi
├── stairl.egi
├── stairr.egi
├── sublist.egi
├── subset.egi
├── takel.egi
├── takelx.egi
├── taker.egi
├── takerx.egi
├── wrap.egi
├── zniq.egi
└── zrep.egi
├── doc
└── example.md
├── img
└── logo.png
├── install.sh
├── lib
└── egzact
│ ├── filters.egi
│ └── utils.egi
├── package.sh
├── pkg
├── .tar2package.yml
├── egzact.deb
└── egzact.rpm
├── test.sh
└── test
├── ShTest.sh
└── lib
├── filters.egi
└── utils.egi
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.egi linguist-language=Egison
2 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: greymd
2 |
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: test
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | - 'develop-**'
8 | - 'bugfix/**'
9 | - 'feature/**'
10 | pull_request:
11 | types:
12 | - opened
13 | - synchronize
14 | - reopened
15 | schedule:
16 | - cron: "0 8 * * 6" # UTC 08:00 (Sat)
17 |
18 | jobs:
19 | build:
20 |
21 | runs-on: ubuntu-latest
22 | if: "!contains(github.event.head_commit.message, 'skip ci')"
23 |
24 | steps:
25 | - uses: actions/checkout@v2
26 | - name: Checkout submodules
27 | run: git submodule update --init --recursive
28 | - name: Install egison
29 | run: |
30 | curl --retry 3 -OL https://git.io/egison.x86_64.deb
31 | sudo dpkg -i ./egison.x86_64.deb
32 | - name: Run tests
33 | run: ./test.sh
34 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "test/shunit2"]
2 | path = test/shunit2
3 | url = https://github.com/kward/shunit2
4 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM phusion/baseimage:latest
2 | MAINTAINER Yamada, Yasuhiro
3 | ENV DEBFULLNAME="Yamada, Yasuhiro" DEBEMAIL=yamadagrep@gmail.com DEBIAN_FRONTEND=noninteractive
4 |
5 | RUN curl --retry 3 -sfSLO https://github.com/greymd/egzact/releases/download/v2.0.0/egzact-2.0.0.deb && \
6 | curl --retry 3 -sfSLO https://github.com/egison/egison-package-builder/releases/download/4.0.0/egison-4.0.0.x86_64.deb
7 |
8 | RUN dpkg -i egzact-2.0.0.deb && \
9 | dpkg -i egison-4.0.0.x86_64.deb
10 |
11 | RUN rm -f egzact-2.0.0.deb && \
12 | rm -f egison-4.0.0.x86_64.deb && \
13 | apt clean && \
14 | rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
15 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Yasuhiro, Yamada
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | [](https://github.com/greymd/egzact/actions?query=workflow%3Atest)
6 |
7 | # Generate flexible patterns on the shell
8 |
9 | How to utilize it? See [examples](./doc/example.md).
10 |
11 | ## New command line tools with three concepts.
12 |
13 | * Enumeration of various patterns from the standard input.
14 | * Useful equivalents for existent Linux commands (inspired by [nixar](https://github.com/askucher/nixar)).
15 | * Controlling records and fields given by particular separator (inspired by [Open-Usp-Tukubai](https://github.com/usp-engineers-community/Open-usp-Tukubai)).
16 |
17 | ## Installation
18 |
19 | egzact requires [Egison](https://www.egison.org/) version 4.1.2.
20 | Following installation procedure include installation of Egison.
21 |
22 | #### Linux users (RHEL compatible distros)
23 |
24 | ```
25 | $ sudo yum install https://git.io/egison-4.1.2.x86_64.rpm ## Install Egison
26 | $ sudo yum install https://git.io/egzact-2.1.1.rpm ## Install egzact
27 | ```
28 |
29 | #### Linux users (Debian base distros)
30 |
31 | ```
32 | $ wget https://git.io/egison-4.1.2.x86_64.deb
33 | $ sudo dpkg -i egison-4.1.2.x86_64.deb ## Install Egison
34 | $ wget https://git.io/egzact-2.1.1.deb
35 | $ sudo dpkg -i egzact-2.1.1.deb ## Install egzact
36 | ```
37 |
38 | #### macOS users
39 |
40 | ```
41 | $ brew install egison/egison/egison ## Install Egison
42 | $ brew install greymd/tools/egzact ## Install egzact
43 | ```
44 |
45 | # Commands
46 | ## Generate multiple results from whole the STDIN
47 |
48 | ### $ `conv`
49 | Print whole the inputs as multiple rows with given number of cols.
50 | Location of each field is shifted over to the left by comparison with one upper line.
51 | The reason why the name is `conv` is, the behavior looks like the **convolution**.
52 |
53 | ```sh
54 | $ seq 10 | conv 2
55 | 1 2
56 | 2 3
57 | 3 4
58 | 4 5
59 | 5 6
60 | 6 7
61 | 7 8
62 | 8 9
63 | 9 10
64 |
65 | $ yes | awk '$0=NR' | conv 3 | head
66 | 1 2 3
67 | 2 3 4
68 | 3 4 5
69 | 4 5 6
70 | 5 6 7
71 | .
72 | .
73 | .
74 |
75 | ```
76 |
77 | ### $ `flat`
78 | Print whole the inputs as multiple rows with given number of cols.
79 | In default, it just removes the new lines.
80 |
81 | ```sh
82 | $ seq 10 | flat
83 | 1 2 3 4 5 6 7 8 9 10
84 | ```
85 |
86 | The behavior is same as `xargs -n N` option. However [Common command line options](#common-command-line-options) like `fs` can be used.
87 |
88 | ```sh
89 | $ seq 10 | flat 2
90 | 1 2
91 | 3 4
92 | 5 6
93 | 7 8
94 | 9 10
95 |
96 | # Comma separeted file
97 | $ cat myfile
98 | AA,AB,AC,AD
99 | BA,BB,BC,BD
100 | CA,CB,CC,CD
101 | DA,DB,DC,DD
102 |
103 | # Field separator(fs) option is useful for keeping comma.
104 | $ cat myfile | flat fs=, 8
105 | AA,AB,AC,AD,BA,BB,BC,BD
106 | CA,CB,CC,CD,DA,DB,DC,DD
107 | ```
108 |
109 | ### $ `slit`
110 |
111 | Divide whole the inputs into given number of rows.
112 |
113 | ```sh
114 | # Print A to Z with 3 rows.
115 | $ echo {A..Z} | slit 3
116 | A B C D E F G H I
117 | J K L M N O P Q R
118 | S T U V W X Y Z
119 |
120 | # Each line's number of field is adjusted to be near each other as much as possible.
121 | $ echo A B C D | slit 3
122 | A B
123 | C
124 | D
125 | ```
126 |
127 | ## Generate multiple results per line.
128 |
129 | ### $ `stairl`
130 |
131 | Generate sublist of the fields.
132 | Each result matches to the *left* side of the original input.
133 | In most cases, it looks *stairs*.
134 |
135 | ```sh
136 | $ echo A B C D | stairl
137 | A
138 | A B
139 | A B C
140 | A B C D
141 | ```
142 |
143 | #### what's going to happen if the input has multiple lines?
144 |
145 | ```sh
146 | $ cat myfile2
147 | AA AB AC AD
148 | BA BB BC BD
149 | CA CB CC CD
150 |
151 | # The command is executed for each line.
152 | $ cat myfile2 | stairl
153 | AA
154 | AA AB
155 | AA AB AC
156 | AA AB AC AD
157 | BA
158 | BA BB
159 | BA BB BC
160 | BA BB BC BD
161 | CA
162 | CA CB
163 | CA CB CC
164 | CA CB CC CD
165 |
166 | # `eos` option is helpful if you want to know where each result is coming from.
167 | $ cat myfile2 | stairl eos=---
168 | AA
169 | AA AB
170 | AA AB AC
171 | AA AB AC AD
172 | ---
173 | BA
174 | BA BB
175 | BA BB BC
176 | BA BB BC BD
177 | ---
178 | CA
179 | CA CB
180 | CA CB CC
181 | CA CB CC CD
182 | ```
183 |
184 | ### $ `stairr`
185 |
186 | Generate sublist of the fields.
187 | Results match to the *right* side of the original input.
188 | In most cases, it looks *stairs*.
189 |
190 | ```sh
191 | $ echo A B C D | stairr
192 | D
193 | C D
194 | B C D
195 | A B C D
196 | ```
197 |
198 | ### $ `sublist`
199 |
200 | Generate all the sublist of the fields.
201 |
202 | ```sh
203 | $ echo A B C D | sublist
204 | A
205 | A B
206 | B
207 | A B C
208 | B C
209 | C
210 | A B C D
211 | B C D
212 | C D
213 | D
214 | ```
215 |
216 | Whole the results is same as `stairl | stairr` when the duplicated lines can be merged.
217 |
218 | ```sh
219 | $ echo A B C D | stairl | stairr | sort | uniq
220 | A
221 | A B
222 | A B C
223 | A B C D
224 | B
225 | B C
226 | B C D
227 | C
228 | C D
229 | D
230 |
231 | $ echo A B C D | sublist | sort | uniq
232 | A
233 | A B
234 | A B C
235 | A B C D
236 | B
237 | B C
238 | B C D
239 | C
240 | C D
241 | D
242 | ```
243 |
244 | ### $ `subset`
245 |
246 | Generate all the subsets of the fields.
247 |
248 | ```sh
249 | $ echo A B C D | subset
250 | A
251 | B
252 | C
253 | D
254 | A B
255 | A C
256 | B C
257 | A D
258 | B D
259 | C D
260 | A B C
261 | A B D
262 | A C D
263 | B C D
264 | A B C D
265 | ```
266 |
267 | ### $ `crops`
268 | Crop all the patterns which matches given string (regular expression).
269 | It includes all the patterns (from shortest to longest match).
270 |
271 | ```sh
272 | $ echo 1110100110 | crops "1.*1"
273 | 11
274 | 111
275 | 11101
276 | 1101
277 | 101
278 | 11101001
279 | 1101001
280 | 101001
281 | 1001
282 | 111010011
283 | 11010011
284 | 1010011
285 | 10011
286 | ```
287 |
288 | If you want to use normal `grep` command for matching query, `stairr fs="" | stairl fs=""` can works with almost same behavior. In addition, it is faster than `crops` because it works with multi processing.
289 |
290 | ```sh
291 | $ echo 1110100110 | stairr fs="" | stairl fs="" | grep -o '1.*1' | sort | uniq
292 | 1001
293 | 10011
294 | 101
295 | 101001
296 | 1010011
297 | 11
298 | 1101
299 | 1101001
300 | 11010011
301 | 111
302 | 11101
303 | 11101001
304 | 111010011
305 | ```
306 |
307 | ### $ `cycle`
308 |
309 | Generate all the circulated patterns.
310 |
311 | ```sh
312 | $ echo A B C D E | cycle
313 | A B C D E
314 | B C D E A
315 | C D E A B
316 | D E A B C
317 | E A B C D
318 | ```
319 |
320 | ### $ `comb`
321 |
322 | Generate **combinations** of N of fields.
323 |
324 | ```
325 | $ echo A B C D | comb 2
326 | A B
327 | A C
328 | B C
329 | A D
330 | B D
331 | C D
332 | ```
333 |
334 | ### $ `perm`
335 |
336 | Generate **permutations** of N of fields.
337 |
338 | ```sh
339 | $ echo A B C D | perm 2
340 | A B
341 | A C
342 | B A
343 | A D
344 | B C
345 | C A
346 | B D
347 | C B
348 | D A
349 | C D
350 | D B
351 | D C
352 | ```
353 |
354 | ### $ `dupl`
355 |
356 | Duplicate lines.
357 |
358 | ```sh
359 | $ echo A B C D | dupl 3
360 | A B C D
361 | A B C D
362 | A B C D
363 | ```
364 |
365 | ### $ `obrev`
366 |
367 | Show given line and reversed line.
368 |
369 | *Obverse and Reverse*
370 |
371 | ```sh
372 | $ echo A B C D | obrev
373 | A B C D
374 | D C B A
375 | ```
376 |
377 |
378 | ## Generate single result for each line.
379 |
380 | ### $ `addl`
381 |
382 | Add str to left side of the input.
383 |
384 | *Add* + *L*eft
385 |
386 | ```sh
387 | $ echo abc | addl ABC
388 | ABCabc
389 | ```
390 |
391 | ### $ `addr`
392 |
393 | Add str to right side of the input.
394 |
395 | *Add* + *R*ight
396 |
397 | ```sh
398 | $ echo abc | addr ABC
399 | abcABC
400 | ```
401 |
402 |
403 | ### $ `mirror`
404 |
405 | Reverse the order of the field.
406 |
407 | ```sh
408 | $ echo A B C D | mirror
409 | D C B A
410 | ```
411 |
412 |
413 | ### $ `takel`
414 |
415 | Print first *N* of fields.
416 |
417 | *Take* + *L*eft
418 |
419 | ```sh
420 | $ echo A B C D | takel 3
421 | A B C
422 | ```
423 |
424 | ### $ `taker`
425 |
426 | Print last *N* of fields.
427 |
428 | *Take* + *R*ight
429 |
430 | ```sh
431 | $ echo A B C D | taker 3
432 | B C D
433 | ```
434 |
435 | ### $ `takelx`
436 |
437 | Print fields from first one to the one which matches given regular expression.
438 |
439 | *Take* + *L*eft + rege*X*
440 |
441 | ```sh
442 | $ echo QBY JCG FCM PAG TPX BQG UGB | takelx "^P.*$"
443 | QBY JCG FCM PAG
444 | ```
445 |
446 | ### $ `takerx`
447 |
448 | Print fields from last one to the one which matches given regular expression.
449 |
450 | *Take* + *R*ight + rege*X*
451 |
452 | ```sh
453 | $ echo QBY JCG FCM PAG TPX BQG UGB | takerx "^P.*$"
454 | PAG TPX BQG UGB
455 | ```
456 |
457 | ### $ `dropl`
458 |
459 | Remove first *N* of fields.
460 |
461 | *Drop* + *L*eft
462 |
463 | ```sh
464 | $ echo QBY JCG FCM PAG TPX BQG UGB | dropl 3
465 | PAG TPX BQG UGB
466 | ```
467 |
468 | ### $ `dropr`
469 |
470 | Remove last *N* of fields.
471 |
472 | *Drop* + *R*ight
473 |
474 | ```sh
475 | $ echo QBY JCG FCM PAG TPX BQG UGB | dropr 3
476 | QBY JCG FCM PAG
477 | ```
478 |
479 | ### $ `zrep`
480 |
481 | Extract particular fields which matches given regular expression.
482 |
483 | eg*Z*act + g*REP*
484 |
485 | ```sh
486 | $ echo 1 2 3 4 5 6 7 8 9 10 | zrep "1"
487 | 1 10
488 | ```
489 |
490 | ### $ `zniq`
491 |
492 | Merge duplicated fields.
493 |
494 | eg*Z*act + u*NIQ*
495 |
496 | ```sh
497 | $ echo aaa bbb ccc aaa bbb | zniq
498 | aaa bbb ccc
499 | ```
500 |
501 | ### $ `wrap`
502 |
503 | Add particular prefix and suffix to each field in accordance with given argument.
504 | `*` is the placeholder which represents each field.
505 |
506 | ```sh
507 | $ echo aaa bbb ccc | wrap "*
"
508 | aaa
bbb
ccc
509 | ```
510 |
511 | ### $ `nestl`
512 |
513 | Nest all the fields with with given argument.
514 | `*` is the placeholder which represents each field.
515 | First field is the most deeply nested element.
516 |
517 | *Nest* + *L*eft
518 |
519 | ```sh
520 | $ echo aaa bbb ccc | nestl "*
"
521 |
aaa
bbb
ccc
522 | ```
523 |
524 | ### $ `nestr`
525 |
526 | Nest all the fields with with given argument.
527 | `*` is the placeholder which represents each field.
528 | Last field is the most deeply nested element.
529 |
530 | *Nest* + *R*ight
531 |
532 | ```sh
533 | $ echo aaa bbb ccc | nestr "*
"
534 | aaa
bbb
ccc
535 | ```
536 |
537 | ## Other commands
538 |
539 | ### $ `addt`
540 |
541 | Add str to top of the input.
542 |
543 | *Add* + *Top*
544 |
545 | ```sh
546 | $ echo abc | addt ABC
547 | ABC
548 | abc
549 | ```
550 |
551 | ### $ `addb`
552 |
553 | Add str to bottom of the input.
554 |
555 | *Add* + *Bottom*
556 |
557 | ```sh
558 | $ echo abc | addb ABC
559 | abc
560 | ABC
561 | ```
562 |
563 | ## Common command line options
564 |
565 | ### `fs`
566 | Field separator.
567 |
568 | * Default value is space ` `.
569 | * Format: `fs=STR`
570 |
571 | Example
572 |
573 | ```sh
574 | $ echo "/usr/local/var/" | stairl fs=/
575 |
576 | /usr
577 | /usr/local
578 | /usr/local/var
579 | /usr/local/var/
580 |
581 | # In case of empty, each character is regarded as a field.
582 | $ echo "abcdefg" | stairl fs=""
583 | a
584 | ab
585 | abc
586 | abcd
587 | abcde
588 | abcdef
589 | abcdefg
590 | ```
591 |
592 | ### `ifs`
593 | Input field separator.
594 | If `fs` is already set, this option is primarily used.
595 |
596 | * Default value is space ` `.
597 | * Format: `ifs=STR`
598 |
599 | Example
600 |
601 | ```sh
602 | $ cat myfile3
603 | AA,AB,AC,AD
604 | BA,BB,BC,BD
605 |
606 | # "," separated input -> " " separated output.
607 | $ cat myfile3 | stairr ifs=","
608 | AD
609 | AC AD
610 | AB AC AD
611 | AA AB AC AD
612 | BD
613 | BC BD
614 | BB BC BD
615 | BA BB BC BD
616 | ```
617 |
618 | ### `ofs`
619 | Output field separator.
620 | If `fs` is already set, this option is primarily used.
621 |
622 | * Default value is space ` `.
623 | * Format: `ofs=STR`
624 |
625 |
626 | Example
627 |
628 | ```sh
629 | $ cat myfile3
630 | AA,AB,AC,AD
631 | BA,BB,BC,BD
632 |
633 | # "," separated input -> "_" separated output.
634 | $ cat myfile3 | cycle ifs="," ofs="_"
635 | AA_AB_AC_AD
636 | AB_AC_AD_AA
637 | AC_AD_AA_AB
638 | AD_AA_AB_AC
639 | BA_BB_BC_BD
640 | BB_BC_BD_BA
641 | BC_BD_BA_BB
642 | BD_BA_BB_BC
643 |
644 | # "," separated input -> tab separated output.
645 | $ cat myfile3 | dupl ifs="," ofs="\t" 2
646 | AA AB AC AD
647 | AA AB AC AD
648 | BA BB BC BD
649 | BA BB BC BD
650 | ```
651 |
652 | ### `eor`
653 | End of record (a.k.a, row).
654 | Result of each line (record) is separated with new line `\n` in default.
655 | This option changes the string for separating each record.
656 |
657 | * Default value is new line `\n`.
658 | * Format: `eor=STR`
659 |
660 | Example
661 |
662 | ```sh
663 | $ cat myfile4
664 | AA AB AC AD
665 | BA BB BC BD
666 |
667 | $ cat myfile4 | stairl
668 | AA # End of record
669 | AA AB # End of record
670 | AA AB AC # End of record
671 | AA AB AC AD # End of set
672 | BA # End of record
673 | BA BB # End of record
674 | BA BB BC # End of record
675 | BA BB BC BD # End of set
676 |
677 | $ cat myfile4 | stairr eor=" @@@ "
678 | AD @@@ AC AD @@@ AB AC AD @@@ AA AB AC AD
679 | BD @@@ BC BD @@@ BB BC BD @@@ BA BB BC BD
680 | ```
681 |
682 | ### `eos`
683 | End of set. Set means, **all results generated from single line**, in this manual.
684 |
685 | * Default value is new line `\n`.
686 | * Format: `eos=STR`
687 |
688 | Example
689 |
690 | ```sh
691 | $ cat myfile4
692 | AA AB AC AD
693 | BA BB BC BD
694 |
695 |
696 | $ cat myfile4 | stairl eos="---"
697 | AA
698 | AA AB
699 | AA AB AC
700 | AA AB AC AD
701 | ---
702 | BA
703 | BA BB
704 | BA BB BC
705 | BA BB BC BD
706 |
707 | $ cat myfile4 | stairl eos="---" eor=" @@@ " ofs=" | "
708 | AA @@@ AA | AB @@@ AA | AB | AC @@@ AA | AB | AC | AD
709 | ---
710 | BA @@@ BA | BB @@@ BA | BB | BC @@@ BA | BB | BC | BD
711 | ```
712 |
713 | ## Tips
714 | A special command line option `each` is available in ``flat``, ``conv`` and ``slit`` commands.
715 | The option changes command's behavior to "each line mode".
716 | In default, those commands handle whole the standard input (STDIN).
717 | However with this option, those commands can read each line and print the result.
718 |
719 | Example
720 |
721 | ```sh
722 | $ cat myfile4
723 | AA AB AC AD
724 | BA BB BC BD
725 |
726 | $ cat myfile4 | flat 3
727 | AA AB AC
728 | AD BA BB
729 | BC BD
730 |
731 | $ cat myfile4 | flat each 3
732 | AA AB AC
733 | AD
734 | BA BB BC
735 | BD
736 |
737 | $ cat myfile4 | conv each 3 eos="---"
738 | AA AB AC
739 | AB AC AD
740 | ---
741 | BA BB BC
742 | BB BC BD
743 | ```
744 |
745 | ## Uninstall
746 |
747 | ```sh
748 | $ make uninstall
749 | ```
750 |
751 | # License
752 | ### Software License
753 | This software is released under the MIT License.
754 | See [LICENSE](./LICENSE)
755 |
756 | ### External Library
757 | [UnitTest.hs](./test/UnitTest.hs) is distributed on [egison/egison](https://github.com/egison/egison) under the [MIT license](https://github.com/egison/egison/blob/master/LICENSE).
758 |
759 | ### Logo
760 |
761 | 
The logo is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.
762 |
--------------------------------------------------------------------------------
/bin/addb.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOptsStr $opts $arg ->
8 | execution printEachLine filterPlain opts arg (stdin ++ [arg])
9 | | _ -> usage
10 |
11 | def usage :=
12 | do print "Usage: addb [OPTIONS] string"
13 | optionUsage
14 | print "tldr:"
15 | print " $ echo abc | addb ABC"
16 | print " abc"
17 | print " ABC"
18 |
--------------------------------------------------------------------------------
/bin/addl.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOptsStr $opts $arg ->
8 | execution printEachLine filterAddl (["ifs=", "ofs="] ++ opts) arg stdin
9 | | _ -> usage
10 |
11 | def usage :=
12 | do print "Usage: addl [OPTIONS] string"
13 | optionUsage2
14 | print "tldr:"
15 | print " $ echo abc | addl ABC"
16 | print " ABCabc"
17 |
--------------------------------------------------------------------------------
/bin/addr.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOptsStr $opts $arg ->
8 | execution printEachLine filterAddr (["ifs=", "ofs="] ++ opts) arg stdin
9 | | _ -> usage
10 |
11 | def usage :=
12 | do print "Usage: addr [OPTIONS] string"
13 | optionUsage2
14 | print "tldr:"
15 | print " $ echo abc | addr ABC"
16 | print " abcABC"
17 |
--------------------------------------------------------------------------------
/bin/addt.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOptsStr $opts $arg ->
8 | execution printEachLine filterPlain opts arg ([arg] ++ stdin)
9 | | _ -> usage
10 |
11 | def usage :=
12 | do print "Usage: addt [OPTIONS] string"
13 | optionUsage
14 | print "tldr:"
15 | print " $ echo abc | addt ABC"
16 | print " ABC"
17 | print " abc"
18 |
--------------------------------------------------------------------------------
/bin/comb.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOptsNum $opts $num ->
8 | execution printEachLine filterComb opts (read num) stdin
9 | | _ -> usage
10 |
11 | def usage :=
12 | do print "Usage: comb [OPTIONS] number"
13 | optionUsage
14 | print "tldr:"
15 | print " $ echo A B C D | comb 2"
16 | print " A B"
17 | print " A C"
18 | print " B C"
19 | print " A D"
20 | print " B D"
21 | print " C D"
22 |
--------------------------------------------------------------------------------
/bin/conv.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | #"each" :: argsCheckOptsNum $opts $arg ->
8 | execution printEachLine filterConvEach opts (numValidation arg) stdin
9 | | #"each" :: argsCheckOpts $opts ->
10 | execution printEachLine filterConvEach opts 1 stdin
11 | | argsCheckOptsNum $opts $arg ->
12 | execution printWholeInput filterConv opts (numValidation arg) stdin
13 | | argsCheckOpts $opts -> execution printWholeInput filterConv opts 1 stdin
14 | | _ -> usage
15 |
16 | def usage :=
17 | do print "Usage: conv [OPTIONS] [number]"
18 | print " conv each [OPTIONS] [number]"
19 | print "Description:"
20 | print " With `each`, it reads & prints results for each line."
21 | optionUsage
22 | print ""
23 | print "tldr:"
24 | print " $ echo A B C D E | conv 2"
25 | print " A B"
26 | print " B C"
27 | print " C D"
28 | print " D E"
29 |
--------------------------------------------------------------------------------
/bin/crops.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOptsStr $opts $arg ->
8 | execution printEachLine filterCrops (["ifs=", "ofs="] ++ opts) arg stdin
9 | | _ -> usage
10 |
11 | def usage :=
12 | do print "Usage: crops [OPTIONS] string"
13 | optionUsage2
14 | print "tldr:"
15 | print " $ echo 1110100110 | crops \"1.*1\""
16 | print " 11"
17 | print " 111"
18 | print " 11101"
19 | print " 1101"
20 | print " 101"
21 | print " 11101001"
22 | print " 1101001"
23 | print " 101001"
24 | print " 1001"
25 | print " 111010011"
26 | print " 11010011"
27 | print " 1010011"
28 | print " 10011"
29 |
--------------------------------------------------------------------------------
/bin/cycle.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOpts $opts -> execution printEachLine filterCycle opts () stdin
8 | | _ -> usage
9 |
10 | def usage :=
11 | do print "Usage: cycle [OPTIONS]"
12 | optionUsage
13 | print "tldr:"
14 | print " $ echo A B C D E | cycle"
15 | print " A B C D E"
16 | print " B C D E A"
17 | print " C D E A B"
18 | print " D E A B C"
19 | print " E A B C D"
20 |
--------------------------------------------------------------------------------
/bin/dropl.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOptsNum $opts $num ->
8 | execution printEachLine filterDropl opts (read num) stdin
9 | | _ -> usage
10 |
11 | def usage :=
12 | do print "Usage: dropl [OPTIONS] number"
13 | optionUsage
14 | print "tldr:"
15 | print " $ echo A B C D E | dropl 2"
16 | print " C D E"
17 |
--------------------------------------------------------------------------------
/bin/dropr.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOptsNum $opts $num ->
8 | execution printEachLine filterDropr opts (read num) stdin
9 | | _ -> usage
10 |
11 | def usage :=
12 | do print "Usage: dropr [OPTIONS] number"
13 | optionUsage
14 | print "tldr:"
15 | print " $ echo A B C D E | dropr 2"
16 | print " A B C"
17 |
--------------------------------------------------------------------------------
/bin/dupl.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOptsNum $opts $num ->
8 | execution printEachLine filterDupl opts (read num) stdin
9 | | _ -> usage
10 |
11 | def usage :=
12 | do print "Usage: dupl [OPTIONS] number"
13 | optionUsage
14 | print "tldr:"
15 | print " $ echo A B C D E | dupl 2"
16 | print " A B C D E"
17 | print " A B C D E"
18 |
--------------------------------------------------------------------------------
/bin/flat.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | #"each" :: argsCheckOptsNum $opts $arg ->
8 | execution printEachLine filterFlat opts (numValidation arg) stdin
9 | | #"each" :: argsCheckOpts $opts ->
10 | execution printEachLine filterFlat opts ARGMAX stdin
11 | | argsCheckOptsNum $opts $arg ->
12 | execution printWholeInput filterFlat opts (numValidation arg) stdin
13 | | argsCheckOpts $opts ->
14 | execution printWholeInput filterFlat opts ARGMAX stdin
15 | | _ -> usage
16 |
17 | def usage :=
18 | do print "Usage: flat [OPTIONS] [number]"
19 | print " flat each [OPTIONS] [number]"
20 | print "Description:"
21 | print " With `each`, it reads & prints results for each line."
22 | optionUsage
23 | print ""
24 | print "tldr:"
25 | print " $ echo A B C D E | flat 2"
26 | print " A B"
27 | print " C D"
28 | print " E"
29 |
--------------------------------------------------------------------------------
/bin/mirror.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOpts $opts -> execution printEachLine filterMirror opts () stdin
8 | | _ -> usage
9 |
10 | def usage :=
11 | do print "Usage: mirror [OPTIONS]"
12 | optionUsage
13 | print "tldr:"
14 | print " $ echo AAA BBB CCC AAA | mirror"
15 | print " AAA CCC AAA BBB"
16 |
--------------------------------------------------------------------------------
/bin/nestl.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOptsStr $opts $arg ->
8 | execution printEachLine filterNestl opts arg stdin
9 | | _ -> usage
10 |
11 | def usage :=
12 | do print "Usage: nestl [OPTIONS] string"
13 | optionUsage
14 | print "tldr:"
15 | print " $ echo AAA BBB CCC | nestl \"*
\""
16 | print "
AAA
BBB CCC "
17 |
--------------------------------------------------------------------------------
/bin/nestr.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOptsStr $opts $arg ->
8 | execution printEachLine filterNestr opts arg stdin
9 | | _ -> usage
10 |
11 | def usage :=
12 | do print "Usage: nestr [OPTIONS] string"
13 | optionUsage
14 | print "tldr:"
15 | print " $ echo AAA BBB CCC | nestr \"*
\""
16 | print " AAA
BBB
CCC
"
17 |
--------------------------------------------------------------------------------
/bin/obrev.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOpts $opts -> execution printEachLine filterObrev opts () stdin
8 | | _ -> usage
9 |
10 | def usage :=
11 | do print "Usage: obrev [OPTIONS]"
12 | optionUsage
13 | print "tldr:"
14 | print " $ echo A B C D E | obrev"
15 | print " A B C D E"
16 | print " E D C B A"
17 |
--------------------------------------------------------------------------------
/bin/perm.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOptsNum $opts $num ->
8 | execution printEachLine filterPerm opts (read num) stdin
9 | | _ -> usage
10 |
11 | def usage :=
12 | do print "Usage: perm [OPTIONS] number"
13 | optionUsage
14 | print "tldr:"
15 | print " $ echo A B C D | perm 2"
16 | print " A B"
17 | print " A C"
18 | print " B A"
19 | print " A D"
20 | print " B C"
21 | print " C A"
22 | print " B D"
23 | print " C B"
24 | print " D A"
25 | print " C D"
26 | print " D B"
27 | print " D C"
28 |
--------------------------------------------------------------------------------
/bin/slit.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | #"each" :: argsCheckOptsNum $opts $arg ->
8 | execution printEachLine filterSlit opts (numValidation arg) stdin
9 | | #"each" :: argsCheckOpts $opts ->
10 | execution printEachLine filterSlit opts ARGMAX stdin
11 | | argsCheckOptsNum $opts $arg ->
12 | execution printWholeInput filterSlit opts (numValidation arg) stdin
13 | | argsCheckOpts $opts ->
14 | execution printWholeInput filterSlit opts ARGMAX stdin
15 | | _ -> usage
16 |
17 | def usage :=
18 | do print "Usage: slit [OPTIONS] [number]"
19 | print " slit each [OPTIONS] [number]"
20 | print "Description:"
21 | print " With `each`, it reads & prints results per line."
22 | optionUsage
23 | print ""
24 | print "tldr:"
25 | print " $ echo A B C D E | slit 2"
26 | print " A B C"
27 | print " D E"
28 |
--------------------------------------------------------------------------------
/bin/stairl.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOpts $opts -> execution printEachLine filterStairl opts () stdin
8 | | _ -> usage
9 |
10 | def usage :=
11 | do print "Usage: stairl [OPTIONS]"
12 | optionUsage
13 | print "tldr:"
14 | print " $ echo A B C D | stairl"
15 | print " A"
16 | print " A B"
17 | print " A B C"
18 | print " A B C D"
19 |
--------------------------------------------------------------------------------
/bin/stairr.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOpts $opts -> execution printEachLine filterStairr opts () stdin
8 | | _ -> usage
9 |
10 | def usage :=
11 | do print "Usage: stairr [OPTIONS]"
12 | optionUsage
13 | print "tldr:"
14 | print " $ echo A B C D | stairr"
15 | print " D"
16 | print " C D"
17 | print " B C D"
18 | print " A B C D"
19 |
--------------------------------------------------------------------------------
/bin/sublist.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOpts $opts -> execution printEachLine filterSublist opts () stdin
8 | | _ -> usage
9 |
10 | def usage :=
11 | do print "Usage: sublist [OPTIONS]"
12 | optionUsage
13 | print "tldr:"
14 | print " $ echo A B C D | sublist"
15 | print " A"
16 | print " A B"
17 | print " B"
18 | print " A B C"
19 | print " B C"
20 | print " C"
21 | print " A B C D"
22 | print " B C D"
23 | print " C D"
24 | print " D"
25 |
--------------------------------------------------------------------------------
/bin/subset.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOpts $opts -> execution printEachLine filterSubset opts () stdin
8 | | _ -> usage
9 |
10 | def usage :=
11 | do print "Usage: subset [OPTIONS]"
12 | optionUsage
13 | print "tldr:"
14 | print " $ echo A B C D | subset"
15 | print " A"
16 | print " B"
17 | print " C"
18 | print " D"
19 | print " A B"
20 | print " A C"
21 | print " B C"
22 | print " A D"
23 | print " B D"
24 | print " C D"
25 | print " A B C"
26 | print " A B D"
27 | print " A C D"
28 | print " B C D"
29 | print " A B C D"
30 |
--------------------------------------------------------------------------------
/bin/takel.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOptsNum $opts $num ->
8 | execution printEachLine filterTakel opts (read num) stdin
9 | | _ -> usage
10 |
11 | def usage :=
12 | do print "Usage: takel [OPTIONS] number"
13 | optionUsage
14 | print "tldr:"
15 | print " $ echo A B C D E | takel 2"
16 | print " A B"
17 |
--------------------------------------------------------------------------------
/bin/takelx.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOptsStr $opts $arg ->
8 | execution printEachLine filterTakelx opts arg stdin
9 | | _ -> usage
10 |
11 | def usage :=
12 | do print "Usage: takelx [OPTIONS] string"
13 | optionUsage
14 | print "tldr:"
15 | print " $ echo QBY JCG FCM PAG TPX BQG UGB | takelx \"^P.*$\""
16 | print " QBY JCG FCM PAG"
17 |
--------------------------------------------------------------------------------
/bin/taker.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOptsNum $opts $num ->
8 | execution printEachLine filterTaker opts (read num) stdin
9 | | _ -> usage
10 |
11 | def usage :=
12 | do print "Usage: taker [OPTIONS] number"
13 | optionUsage
14 | print "tldr:"
15 | print " $ echo A B C D E | taker 2"
16 | print " D E"
17 |
--------------------------------------------------------------------------------
/bin/takerx.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOptsStr $opts $arg ->
8 | execution printEachLine filterTakerx opts arg stdin
9 | | _ -> usage
10 |
11 | def usage :=
12 | do print "Usage: takerx [OPTIONS] string"
13 | optionUsage
14 | print "tldr:"
15 | print " $ echo QBY JCG FCM PAG TPX BQG UGB | takerx \"^P.*$\""
16 | print " PAG TPX BQG UGB"
17 |
--------------------------------------------------------------------------------
/bin/wrap.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOptsStr $opts $arg ->
8 | execution printEachLine filterWrap opts arg stdin
9 | | _ -> usage
10 |
11 | def usage :=
12 | do print "Usage: wrap [OPTIONS] string"
13 | optionUsage
14 | print "tldr:"
15 | print " $ echo AAA BBB CCC | wrap \"*
\""
16 | print " AAA
BBB
CCC
"
17 |
--------------------------------------------------------------------------------
/bin/zniq.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOpts $opts -> execution printEachLine filterZniq opts () stdin
8 | | _ -> usage
9 |
10 | def usage :=
11 | do print "Usage: zniq [OPTIONS]"
12 | optionUsage
13 | print "tldr:"
14 | print " $ echo aaa bbb ccc aaa bbb | zniq"
15 | print " aaa bbb ccc"
16 |
--------------------------------------------------------------------------------
/bin/zrep.egi:
--------------------------------------------------------------------------------
1 | loadFile "../lib/egzact/utils.egi"
2 |
3 | loadFile "../lib/egzact/filters.egi"
4 |
5 | def main :=
6 | \match as list string with
7 | | argsCheckOptsStr $opts $arg ->
8 | execution printEachLine filterZrep opts arg stdin
9 | | _ -> usage
10 |
11 | def usage :=
12 | do print "Usage: zrep [OPTIONS] string"
13 | optionUsage
14 | print "tldr:"
15 | print " $ echo 1 2 3 4 5 6 7 8 9 10 | zrep \"1\""
16 | print " 1 10"
17 |
--------------------------------------------------------------------------------
/doc/example.md:
--------------------------------------------------------------------------------
1 | # "egzact" Examples
2 |
3 | ## Enumerate all the possible parent domains from the sub domain.
4 |
5 | Command: `stairr`
6 |
7 | ```bash
8 | $ echo hoge.huga.pre.cure.example.com | stairr fs=.
9 | com
10 | example.com
11 | cure.example.com
12 | pre.cure.example.com
13 | huga.pre.cure.example.com
14 | hoge.huga.pre.cure.example.com
15 | ```
16 |
17 | ## Enumerate all the possible parent directories from the sub directory.
18 |
19 | Command: `stairl`
20 |
21 | ```bash
22 | $ pwd | stairl fs=/
23 | /usr
24 | /usr/local
25 | /usr/local/bin
26 | ```
27 |
28 | ## Enumerate all the possible FQDN
29 |
30 | Command: `stairr` `stairl`
31 |
32 | ```bash
33 | $ echo aaa.bbb.ccc.example.com/a/b/c/d | stairr fs=. | stairl fs=/
34 | com
35 | com/a
36 | com/a/b
37 | com/a/b/c
38 | com/a/b/c/d
39 | example.com
40 | example.com/a
41 | example.com/a/b
42 | example.com/a/b/c
43 | example.com/a/b/c/d
44 | ccc.example.com
45 | ccc.example.com/a
46 | ccc.example.com/a/b
47 | ccc.example.com/a/b/c
48 | ccc.example.com/a/b/c/d
49 | bbb.ccc.example.com
50 | bbb.ccc.example.com/a
51 | bbb.ccc.example.com/a/b
52 | bbb.ccc.example.com/a/b/c
53 | bbb.ccc.example.com/a/b/c/d
54 | aaa.bbb.ccc.example.com
55 | aaa.bbb.ccc.example.com/a
56 | aaa.bbb.ccc.example.com/a/b
57 | aaa.bbb.ccc.example.com/a/b/c
58 | aaa.bbb.ccc.example.com/a/b/c/d
59 | ```
60 |
61 | ## Enumerate all the `that ... that` parts from [the word sequence](https://en.wikipedia.org/wiki/That_that_is_is_that_that_is_not_is_not_is_that_it_it_is) .
62 |
63 | Command: `stairr` `stairl`
64 |
65 | ``stairl | stairr`` generates all the sublists from the input.
66 |
67 | ```bash
68 | $ echo "That that is is that that is not is not is that it it is" | stairl | stairr | grep -o "that.*that" | sort | uniq
69 | that is is that
70 | that is is that that
71 | that is is that that is not is not is that
72 | that is not is not is that
73 | that that
74 | that that is not is not is that
75 | ```
76 |
77 | ## Split the file into 17 indivisual files.
78 |
79 | Command: `slit`
80 |
81 | ```sh
82 | $ seq $(awk 'END{print NR}' mytext) | slit 17 | awk '{print "sed -n "$1","$NF"p mytext > mytext."NR}'
83 | sed -n 1,2p mytext > mytext.1
84 | sed -n 3,4p mytext > mytext.2
85 | sed -n 5,6p mytext > mytext.3
86 | sed -n 7,8p mytext > mytext.4
87 | sed -n 9,10p mytext > mytext.5
88 | sed -n 11,12p mytext > mytext.6
89 | sed -n 13,14p mytext > mytext.7
90 | sed -n 15,15p mytext > mytext.8
91 | sed -n 16,16p mytext > mytext.9
92 | sed -n 17,17p mytext > mytext.10
93 | sed -n 18,18p mytext > mytext.11
94 | sed -n 19,19p mytext > mytext.12
95 | sed -n 20,20p mytext > mytext.13
96 | sed -n 21,21p mytext > mytext.14
97 | sed -n 22,22p mytext > mytext.15
98 | sed -n 23,23p mytext > mytext.16
99 | sed -n 24,24p mytext > mytext.17
100 |
101 | # Execute
102 | $ seq $(awk 'END{print NR}' mytext) | slit 17 | awk '{print "sed -n "$1","$NF"p mytext > mytext."NR}' | sh
103 | ```
104 |
105 | ## Generate [Bi-gram](https://en.wikipedia.org/wiki/N-gram) from the poem.
106 |
107 | Command: `conv`
108 |
109 | ```bash
110 | $ echo "If a man understands a poem, he shall have troubles." | conv 2
111 | If a
112 | a man
113 | man understands
114 | understands a
115 | a poem,
116 | poem, he
117 | he shall
118 | shall have
119 | have troubles.
120 | ```
121 |
122 | ## Create a zip file nested 100 times.
123 |
124 | Command: `conv` `mirror` `addl`
125 |
126 | ```bash
127 | $ echo file {1..100}.zip | conv 2 | mirror | addl "zip "
128 | zip 1.zip file
129 | zip 2.zip 1.zip
130 | zip 3.zip 2.zip
131 | zip 4.zip 3.zip
132 | zip 5.zip 4.zip
133 | zip 6.zip 5.zip
134 | zip 7.zip 6.zip
135 | zip 8.zip 7.zip
136 | zip 9.zip 8.zip
137 | zip 10.zip 9.zip
138 | ...
139 |
140 | # Execute
141 | $ echo file {1..100}.zip | conv 2 | mirror | addl "zip " | sh
142 |
143 | $ unzip -Z -2 100.zip
144 | 99.zip
145 | ```
146 |
147 | ## Calculate the approximation of Napier's Constant
148 |
149 | Command: `flat` `stairl` `wrap` `addl`
150 |
151 | ```bash
152 | $ seq 10 | flat | stairl ofs="*" | flat | wrap ofs="+" '1/(*)' | addl "1+" | bc -l
153 | 2.71828180114638447967
154 | ```
155 |
156 | ## Calculate the approximation of PI
157 |
158 | Command: `addr` `mirror` `flat` `nestr` `wrap`
159 |
160 | ```bash
161 | $ seq 1 2 50 | nl | awk '$1=$1"^2/"' | addr '+' | mirror | flat | addr ' 1' | nestr '(*)' | wrap ifs="_" '(4/ *)' | bc -l
162 | 3.14159265358979323651
163 | ```
164 |
165 | ## Generate too nexted DOM element
166 |
167 | Command: `nestr`
168 |
169 | ```bash
170 | $ echo {1..10} | nestr "*
"
171 | 1
2
3
4
5
6
7
8
9
10
172 | ```
173 |
174 | ## Generate too nexted JSON element
175 |
176 | Command: `wrap` `addr` `nestr`
177 |
178 | `jq` command is necessary.
179 |
180 | ```bash
181 | $ echo A B C D E F | wrap '"*":' | addr "\"G\"" | nestr "{*}" | jq .
182 | {
183 | "A": {
184 | "B": {
185 | "C": {
186 | "D": {
187 | "E": {
188 | "F": "G"
189 | }
190 | }
191 | }
192 | }
193 | }
194 | }
195 | ```
196 |
197 | ## Easily create the table DOM element from the space separated input.
198 |
199 | Command: `wrap` `flat` `addt` `addb`
200 |
201 | ```
202 | $ COL=3
203 | $ echo A B C D E F G H | wrap '* | ' | flat $COL | wrap fs=_ '*
' | addt ''
204 |
205 | A | B | C |
206 | D | E | F |
207 | G | H |
208 |
209 | ```
210 |
--------------------------------------------------------------------------------
/img/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/greymd/egzact/3f3c5661e5bdf60e663436d1185364e20341eeb4/img/logo.png
--------------------------------------------------------------------------------
/install.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -ue
3 |
4 | readonly THIS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-${(%):-%N}}")" && pwd)"
5 | readonly BINMODE=755
6 | readonly LIBMODE=644
7 | readonly SRCMODE=644
8 | readonly PREFIX="${1:-/usr/local}"
9 | readonly PREFIX_BIN="${PREFIX}/bin"
10 | readonly PREFIX_LIB="${PREFIX}/lib/egzact"
11 | readonly PREFIX_SRC="${PREFIX}/lib/egzact/src"
12 |
13 | _installbin () {
14 | local _mode="$1" ;shift
15 | local _src="$1" ;shift
16 | local _dst="$1" ;shift
17 | cat < "${_dst}"
18 | #!/bin/bash
19 | exec egison ${_src} -- \$@
20 | TEMPLATE
21 | chmod "${_mode}" "${_dst}"
22 | }
23 |
24 | _install () {
25 | local _mode="$1" ;shift
26 | local _src="$1" ;shift
27 | local _dst="$1" ;shift
28 | echo "sed \"1,3s:\\.\\.:${PREFIX}:\" \"${_src}\" > \"${_dst}\""
29 | sed "1,3s:\\.\\.:${PREFIX}:" "${_src}" > "${_dst}"
30 | chmod "${_mode}" "${_dst}"
31 | }
32 |
33 | # Install (bin/src)
34 | echo install -d "${PREFIX_SRC}"
35 | install -d "${PREFIX_SRC}"
36 | echo install -d "${PREFIX_BIN}"
37 | install -d "${PREFIX_BIN}"
38 | {
39 | cd "${THIS_DIR}/bin"
40 | for _file in *.egi ;do
41 | _src="${PREFIX_SRC}/${_file}"
42 | _install "${SRCMODE}" "${_file}" "${_src}"
43 | _installbin "${BINMODE}" "${_src}" "${PREFIX_BIN}/${_file/.egi}"
44 | done
45 | }
46 |
47 | # Install (lib)
48 | echo install -d "${PREFIX_LIB}"
49 | install -d "${PREFIX_LIB}"
50 | {
51 | cd "${THIS_DIR}/lib/egzact"
52 | for _file in *.egi ;do
53 | _install "${LIBMODE}" "${_file}" "${PREFIX_LIB}/${_file}"
54 | done
55 | }
56 |
--------------------------------------------------------------------------------
/lib/egzact/filters.egi:
--------------------------------------------------------------------------------
1 | def PHOLDER := "\\*"
2 |
3 | def filterPlain str line := [line]
4 |
5 | def filterAddl str line := [str :: line]
6 |
7 | def filterAddr str line := [line ++ [str]]
8 |
9 | def filterMirror str line := [reverse line]
10 |
11 | def filterObrev str line := [line, reverse line]
12 |
13 | def filterCycle num line :=
14 | matchAll line as list string with
15 | | ($x & _) ++ ($xs & ![]) -> (concat [xs, x])
16 |
17 | def filterComb num line :=
18 | let minNum := min num (length line)
19 | in matchAll line as list string with
20 | | loop $i (1, minNum)
21 | (_ ++ $a_i :: ...)
22 | _ -> map 1#a_%1 (between 1 minNum)
23 |
24 | def filterPerm num line :=
25 | let minNum := min num (length line)
26 | in matchAll line as multiset string with
27 | | loop $i (1, minNum, _)
28 | ($a_i :: ...)
29 | _ -> map 1#a_%1 (between 1 minNum)
30 |
31 | def filterConvEach num line := filterConv (min num (length line)) line
32 |
33 | def filterConv num line :=
34 | matchAll line as list string with
35 | | _ ++ (loop $i (1, num, _)
36 | ($a_i :: ...)
37 | _) -> map 1#a_%1 (between 1 num)
38 |
39 | def filterDupl num line := take num (repeat1 line)
40 |
41 | def filterFlat num line :=
42 | match line as list string with
43 | | loop $i (1, num, _)
44 | ($a_i :: ...)
45 | $xs -> map 1#a_%1 (between 1 num) :: filterFlat num xs
46 | | $x ++ $xs :: [] -> [x ++ [xs]]
47 | | [] -> []
48 |
49 | def filterSlit num line :=
50 | let execPartition partNums ls :=
51 | match ls as list integer with
52 | | [] -> []
53 | | loop $n (1, head partNums, _)
54 | ($a_n :: ...)
55 | $rest ->
56 | concat
57 | [ [map 1#a_%1 (between 1 (head partNums))]
58 | , execPartition (tail partNums) rest ]
59 | in execPartition (equalizedPartitionNums (length line) num) line
60 |
61 | -- Devide a number into the collection which has "num-length" of elements.
62 | -- Returns a "integer partition" which equalized each element as much as possible.
63 | -- equalizedPartitionNums 100 10 -- => [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
64 | -- equalizedPartitionNums 100 6; => [17, 17, 17, 17, 16, 16]
65 | def equalizedPartitionNums num numLength :=
66 | let upperNum := ceiling (rtof (num / numLength))
67 | lowerNum := upperNum - 1
68 | lowerNumCount := upperNum * numLength - num
69 | upperNumCount := numLength - lowerNumCount
70 | in concat
71 | [ take upperNumCount (repeat1 upperNum)
72 | , take lowerNumCount (repeat1 lowerNum) ]
73 |
74 | def filterSublist empty line :=
75 | matchAll line as list string with
76 | | _ ++ ($x & ![]) ++ _ -> x
77 |
78 | def filterSubset empty line :=
79 | matchAll line as set string with
80 | | ($x & ![]) ++ _ -> x
81 |
82 | def filterStairl empty line :=
83 | matchAll line as list string with
84 | | ($x & ![]) ++ $xs -> (x)
85 |
86 | def filterStairr empty line :=
87 | matchAll line as list string with
88 | | nioj ($x & ![]) $xs -> (x)
89 |
90 | def filterTakel num line :=
91 | let minNum := min num (length line)
92 | in [(take minNum line)]
93 |
94 | def filterTaker num line :=
95 | let minNum := min num (length line)
96 | in [drop (length line - minNum) line]
97 |
98 | def filterTakelx str line :=
99 | [ match line as list string with
100 | | $left ++ ($elem & ?1#(not (isEmpty (regex str %1))) & ![]) :: _ ->
101 | left ++ [elem]
102 | | _ -> [] ]
103 |
104 | def filterTakerx str line :=
105 | [ match line as list string with
106 | | nioj $right (snoc ($elem & ?1#(not (isEmpty (regex str %1))) & ![]) _) ->
107 | [elem] ++ right
108 | | _ -> [] ]
109 |
110 | def filterDropl num line :=
111 | let minNum := min num (length line)
112 | in [drop minNum line]
113 |
114 | def filterDropr num line :=
115 | let minNum := min num (length line)
116 | in [take (length line - minNum) line]
117 |
118 | def filterZrep str line :=
119 | [ match line as list string with
120 | | $left ++ ($elem & ?1#(not (isEmpty (regex str %1))) & ![]) :: $right ->
121 | concat ([elem] :: filterZrep str right)
122 | | _ -> [] ]
123 |
124 | def filterZniq str line := [uniqueAs string line]
125 |
126 | def filterWrap str line :=
127 | let (pre, pl, suf) := head (regex PHOLDER str)
128 | in filterWrapImpl pre suf line
129 |
130 | def filterWrapImpl pre suf line :=
131 | [ match line as list string with
132 | | _ ++ $elem :: $right ->
133 | concat ([S.concat [pre, elem, suf]] :: filterWrapImpl pre suf right)
134 | | _ -> [] ]
135 |
136 | def filterNestl str line :=
137 | let (pre, pl, suf) := head (regex PHOLDER str)
138 | in [foldl 2#(concat [[pre], %1, [%2], [suf]]) [] line]
139 |
140 | def filterNestr str line :=
141 | let (pre, pl, suf) := head (regex PHOLDER str)
142 | in [foldr 2#(concat [[pre], [%1], %2, [suf]]) [] line]
143 |
144 | -- > removeEmptyElement ["11","22",[],"1"]
145 | -- ["11", "22", "1"]
146 | def removeEmptyElement results := filter 1#(not (isEmpty %1)) results
147 |
148 | -- > extractMachedStr [[("123","AAA","")],[("","BBB","")]]
149 | -- [["AAA"], ["BBB"]]
150 | def extractMachedStr results := map (\(_, elem, _) -> [elem]) (map head results)
151 |
152 | -- > filterCrops "1.1$" ["123","131","222"]
153 | -- [["131"]]
154 | def filterCrops str line :=
155 | uniqueAs (list string)
156 | (extractMachedStr
157 | (removeEmptyElement
158 | (matchAll line as list string with
159 | | _ ++ ($x & ![]) ++ _ -> regex str (S.concat x))))
160 |
--------------------------------------------------------------------------------
/lib/egzact/utils.egi:
--------------------------------------------------------------------------------
1 | def ARGMAX := 65535
2 |
3 | def S.isNats str := not (isEmpty (regex "^[1-9][0-9]*$" str))
4 |
5 | def argsCheckOpts := \opts => (~opts & ?checkOpts) ++ []
6 |
7 | def argsCheckOptsNum :=
8 | \opts arg => (~opts & ?checkOpts) ++ (~arg & ?S.isNats) :: []
9 |
10 | def argsCheckOptsStr := \opts arg => (~opts & ?checkOpts) ++ ~arg :: []
11 |
12 | def checkOpts opts :=
13 | match opts as list string with
14 | | [] -> True
15 | | loop $n (1, length opts, _)
16 | (?1#(not (isEmpty (regex "=" %1))) :: ...)
17 | [] -> True
18 | | _ -> False
19 |
20 | def numValidation num :=
21 | if isInteger num
22 | then if num > 0 then min num ARGMAX else ARGMAX
23 | else if isString num then min (read num) ARGMAX else ARGMAX
24 |
25 | def optionUsage :=
26 | do print "OPTIONS:"
27 | print " fs=STR Field separator."
28 | print " ifs=STR Input field separator."
29 | print " ofs=STR Output field separator."
30 | print " eor=STR End of record."
31 | print " eos=STR End of set."
32 |
33 | def optionUsage2 :=
34 | do print "OPTIONS:"
35 | print " eor=STR End of record."
36 | print " eos=STR End of set."
37 |
38 | def execution thisPrinter thisFilter thisOpts thisArg thisInput :=
39 | let (ifs, ofs, eor, eos, eof) := setDefaultOpts (opts2hash thisOpts)
40 | in thisPrinter thisFilter thisArg ifs ofs eor eos eof thisInput
41 |
42 |
43 | -- Set default value of each command line options.
44 | def setDefaultOpts opts :=
45 | ( setDefaultValue [opts "ifs", opts "fs", " "] -- input field separator
46 | , setDefaultValue [opts "ofs", opts "fs", " "] -- output field separator
47 | , setDefaultValue [opts "eor", "\n"] -- output row separator
48 | , setDefaultValue2 [opts "eos", "\n"] -- output set separator
49 | , setDefaultValue [opts "eof", "\n"] ) -- end of file
50 |
51 | -- Infinite input stream
52 | def stdin := takeWhile 1#(not (EOF = %1)) (recursiveRead readLine)
53 |
54 | def recursiveRead proc :=
55 | (if io (isEof ()) then EOF else io (proc ())) :: recursiveRead proc
56 |
57 | -- Print whole the input stream with specified fieds.
58 | def printWholeInput filter args ifs ofs eor eos eof inf :=
59 | each
60 | 1#(write (S.append (joinString ofs %1) eor))
61 | (filter args (splitWholeInput ifs inf))
62 |
63 | -- Print each lines with specified fields.
64 | def printEachLine filter args ifs ofs eor eos eof inf :=
65 | each
66 | write
67 | (intersperse2
68 | eos
69 | (map
70 | 1#(twocol2string ofs eor %1)
71 | (map 1#(filter args %1) (splitEachLine ifs inf))) ++ [eof])
72 |
73 | -- Returns the string which is found most early.
74 | def setDefaultValue ls :=
75 | match ls as list something with
76 | | _ ++ ($x & !#() & ?isString) :: $xs -> x
77 |
78 | -- When the first element is string, put it between new lines.
79 | def setDefaultValue2 ls :=
80 | match ls as list something with
81 | | ($x & !#() & ?isString) :: $xs -> S.concat ["\n", x, "\n"]
82 | | _ -> setDefaultValue ls
83 |
84 | -- Define Hash
85 | -- Convert string collection to function which acts like key-value hash.
86 | -- ["P1=A","P2=B"]
87 | -- match as something with
88 | -- | #"P1" -> "A"
89 | -- | #"P2" -> "B"
90 | -- Example:
91 | -- > myhash := opts2hash ["A=B", "C=D"]
92 | -- > myhash "A"
93 | -- > "B"
94 | def opts2hash args :=
95 | read $ S.concat [ "\\match as something with\n"
96 | , S.concat (map 1#(let (key, _, val) := head (regex "=" %1)
97 | in S.concat [" | #", show key, " -> ", show val, "\n"]) args)
98 | , " | _ -> []\n"
99 | ]
100 |
101 | -- Convert two-dimensional-collection to string
102 | -- > twocol2string "-" "@" [["a","b","c"],["d","e","f"],["g"]] -- => "a-b-c@d-e-f@g"
103 | def twocol2string fieldSep rowSep cols :=
104 | joinString rowSep (map 1#(joinString fieldSep %1) cols)
105 |
106 | -- Escape particular character
107 | -- Example: escaping "a" character.
108 | -- > (escapeChars 'a') ['a','b','c','a','b','d'] -- => ['\', 'a', 'b', 'c', '\', 'a', 'b', 'd']
109 | def escapeChars target :=
110 | \match as list char with
111 | | [] -> []
112 | | ($c & #target) :: $cs -> ['\\', c] ++ (escapeChars target) cs
113 | | $c :: $cs -> [c] ++ (escapeChars target) cs
114 |
115 | -- joinString "," ["a","b","c"] -- "a,b,c"
116 | def joinString fs ls :=
117 | match ls as list string with
118 | | [] -> ""
119 | | ($lst & ?isString) :: [] -> lst
120 | | $x :: $xs -> S.append (S.append x fs) (joinString fs xs)
121 |
122 | -- new split-string function which can deal with empty separator
123 | def S.split2 delim ls :=
124 | if S.isEmpty delim then map 1#(pack [%1]) (unpack ls) else S.split delim ls
125 |
126 | -- splitWholeInput " " ["a b c","1 2 3"] -- => ["a","b","c","1","2","3"]
127 | def splitWholeInput str line :=
128 | match line as list string with
129 | | [] -> []
130 | | $x :: $xs -> concat [S.split2 str x, splitWholeInput str xs]
131 |
132 | -- splitEachLine " " ["a b c","1 2 3"] -- => [["a", "b", "c"], ["1", "2", "3"]]
133 | -- splitEachLine "" ["a b c","1 2 3"] -- => [["a", " ", "b", " ", "c"], ["1", " ", "2", " ", "3"]]
134 | def splitEachLine str line :=
135 | match line as list string with
136 | | [] -> []
137 | | $x :: $xs -> [S.split2 str x] ++ splitEachLine str xs
138 |
139 | -- The behavior is same as intersperse.
140 | -- But it works even the input is infinite stream.
141 | -- intersperse2 "---" ["a b c","1 2 3","e f g"] -- => ["a b c", "---", "1 2 3", "---", "e f g"]
142 | def intersperse2 str line :=
143 | match line as list string with
144 | | $x :: [] -> [x]
145 | | $x :: $xs -> [x] ++ [str] ++ intersperse2 str xs -- first and before last element
146 |
--------------------------------------------------------------------------------
/package.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -ue
3 | readonly THIS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-${(%):-%N}}")" && pwd)"
4 | trap 'rm -f "${THIS_DIR}"/egzact.tar.gz' EXIT
5 | {
6 | cd "${THIS_DIR}"
7 | rm -f "${THIS_DIR}"/egzact.tar.gz
8 | docker run -v "${PWD}":/work -i phusion/baseimage:latest /bin/bash -c '
9 | _pholder="@@@@@REPLACE_HERE@@@@@"
10 | /work/install.sh /usr/$_pholder
11 | shopt -s globstar
12 | sed -i "s|/$_pholder||g" /usr/$_pholder/{bin/*,lib/**/*.egi}
13 | cp /work/pkg/.tar2package.yml /usr/$_pholder/
14 | tar zcvf /work/egzact.tar.gz -C "/usr/$_pholder" bin lib .tar2package.yml
15 | '
16 | _version="$(awk "/^version/{print \$NF}" "${THIS_DIR}"/pkg/.tar2package.yml)"
17 | docker run -i greymd/tar2rpm:1.0.1 < egzact.tar.gz > "${THIS_DIR}"/pkg/egzact-"${_version}".rpm
18 | docker run -i greymd/tar2deb:1.0.1 < egzact.tar.gz > "${THIS_DIR}"/pkg/egzact-"${_version}".deb
19 | }
20 |
--------------------------------------------------------------------------------
/pkg/.tar2package.yml:
--------------------------------------------------------------------------------
1 | name : egzact
2 | cmdname : egzact
3 | summary : Strengthen weak points of the shell
4 | description : New command line tools with three concepts.
5 | version : 2.1.1
6 | changelog : Fix rpm/deb package misconfiguration
7 | url : https://github.com/greymd/egzact
8 | author : Yasuhiro, Yamada
9 | email : yamadagrep@gmail.com
10 | libdir : /usr/lib
11 |
--------------------------------------------------------------------------------
/pkg/egzact.deb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/greymd/egzact/3f3c5661e5bdf60e663436d1185364e20341eeb4/pkg/egzact.deb
--------------------------------------------------------------------------------
/pkg/egzact.rpm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/greymd/egzact/3f3c5661e5bdf60e663436d1185364e20341eeb4/pkg/egzact.rpm
--------------------------------------------------------------------------------
/test.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | THIS_DIR="$(cd "$(dirname "$0")" && pwd)"
3 |
4 | # Unit testing
5 | for f in "$THIS_DIR"/test/lib/*.egi; do
6 | result="$(egison -t "$f")"
7 | if grep -q '^#f' <<<"$result"; then
8 | echo "$f: Unit tests failed" >&2
9 | echo "$result" >&2
10 | else
11 | echo "$f: Unit tests succeeded" >&2
12 | fi
13 | done
14 |
15 | # Integration testing
16 | sh "$THIS_DIR/test/ShTest.sh"
17 |
--------------------------------------------------------------------------------
/test/ShTest.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | TEST_DIR=$(dirname "$0")
3 | BIN_DIR="${TEST_DIR}/../bin"
4 |
5 | setUp(){
6 | cd "$BIN_DIR" 2> /dev/null || exit 1
7 | }
8 |
9 | test_addt() {
10 | result=$(echo abc | egison ./addt.egi -- ABC)
11 | assertEquals "ABC
12 | abc" "${result}"
13 |
14 | result=$(echo a bc | egison ./addt.egi -- ofs=_ eos=--- A)
15 | assertEquals "A
16 | ---
17 | a_bc" "${result}"
18 | }
19 |
20 | test_addb() {
21 | result=$(echo abc | egison ./addb.egi -- ABC)
22 | assertEquals "abc
23 | ABC" "${result}"
24 |
25 | result=$(echo a bc | egison ./addb.egi -- ofs=_ eos=--- A)
26 | assertEquals "a_bc
27 | ---
28 | A" "${result}"
29 | }
30 |
31 | test_addl() {
32 | result=$(echo abc | egison ./addl.egi -- ABC)
33 | assertEquals "ABCabc" "${result}"
34 | }
35 |
36 | test_addr() {
37 | result=$(echo abc | egison ./addr.egi -- ABC)
38 | assertEquals "abcABC" "${result}"
39 | }
40 |
41 | test_comb() {
42 | result=$(echo A B C D | egison ./comb.egi -- 2)
43 | assertEquals "A B
44 | A C
45 | B C
46 | A D
47 | B D
48 | C D" "${result}"
49 |
50 | result=$(printf "A B C\n1 2 3" | egison ./comb.egi -- eos="---" 2)
51 | assertEquals "A B
52 | A C
53 | B C
54 | ---
55 | 1 2
56 | 1 3
57 | 2 3" "${result}"
58 |
59 | result=$(echo A B C D | egison ./comb.egi -- 100)
60 | assertEquals "A B C D" "${result}"
61 |
62 | }
63 |
64 | test_conv() {
65 | result=$(seq 10 | xargs | egison ./conv.egi)
66 | assertEquals "1
67 | 2
68 | 3
69 | 4
70 | 5
71 | 6
72 | 7
73 | 8
74 | 9
75 | 10" "${result}"
76 |
77 | result=$(seq 10 | egison ./conv.egi -- eor=@)
78 | assertEquals "1@2@3@4@5@6@7@8@9@10@" "${result}"
79 |
80 | result=$(seq 10 | xargs -n 5 | egison ./conv.egi -- each)
81 | assertEquals "1
82 | 2
83 | 3
84 | 4
85 | 5
86 | 6
87 | 7
88 | 8
89 | 9
90 | 10" "${result}"
91 |
92 | result=$(seq 10 | egison ./conv.egi -- 2)
93 | assertEquals "1 2
94 | 2 3
95 | 3 4
96 | 4 5
97 | 5 6
98 | 6 7
99 | 7 8
100 | 8 9
101 | 9 10" "${result}"
102 |
103 | result=$(printf "AA AB AC AD\nBA BB BC BD" | egison ./conv.egi -- 3)
104 | assertEquals "AA AB AC
105 | AB AC AD
106 | AC AD BA
107 | AD BA BB
108 | BA BB BC
109 | BB BC BD" "${result}"
110 |
111 | result=$(printf "AA AB AC AD\nBA BB BC BD" | egison ./conv.egi -- ofs='"' 3)
112 | assertEquals 'AA"AB"AC
113 | AB"AC"AD
114 | AC"AD"BA
115 | AD"BA"BB
116 | BA"BB"BC
117 | BB"BC"BD' "${result}"
118 |
119 | result=$(echo 'AA"AB"AC"AD"BA"BB"BC"BD' | egison ./conv.egi -- ifs="\"" ofs="\"\"" 3)
120 | assertEquals 'AA""AB""AC
121 | AB""AC""AD
122 | AC""AD""BA
123 | AD""BA""BB
124 | BA""BB""BC
125 | BB""BC""BD' "${result}"
126 |
127 | result=$(printf "AA AB AC AD\nBA BB BC BD" | egison ./conv.egi -- each 3)
128 | assertEquals "AA AB AC
129 | AB AC AD
130 | BA BB BC
131 | BB BC BD" "${result}"
132 |
133 | result=$(printf "AA AB AC AD\nBA BB BC BD" | egison ./conv.egi -- each eos="@@@" 3)
134 | assertEquals "AA AB AC
135 | AB AC AD
136 | @@@
137 | BA BB BC
138 | BB BC BD" "${result}"
139 | }
140 |
141 | test_flat() {
142 | result=$(seq 10 | egison ./flat.egi)
143 | assertEquals "1 2 3 4 5 6 7 8 9 10" "${result}"
144 |
145 | result=$(seq 10 | tr ' ' '@' | egison ./flat.egi -- fs=@)
146 | assertEquals "1@2@3@4@5@6@7@8@9@10" "${result}"
147 |
148 | result=$(seq 10 | egison ./flat.egi -- 5 | egison ./flat.egi each)
149 | assertEquals "1 2 3 4 5
150 | 6 7 8 9 10" "${result}"
151 |
152 | result=$(seq 10 | egison ./flat.egi -- 2)
153 | assertEquals "1 2
154 | 3 4
155 | 5 6
156 | 7 8
157 | 9 10" "${result}"
158 |
159 | # result=$(seq 10 | egison ./flat.egi -- ofs='"\' 2)
160 | # assertEquals '1"\2
161 | # 3"\4
162 | # 5"\6
163 | # 7"\8
164 | # 9"\10' "${result}"
165 |
166 | result=$(printf "AA AB AC AD\nBA BB BC BD" | egison ./flat.egi -- 3)
167 | assertEquals "AA AB AC
168 | AD BA BB
169 | BC BD" "${result}"
170 |
171 | result=$(printf "AA AB AC AD\nBA BB BC BD" | egison ./flat.egi -- each 3)
172 | assertEquals "AA AB AC
173 | AD
174 | BA BB BC
175 | BD" "${result}"
176 |
177 | result=$(printf "AA AB AC AD\nBA BB BC BD" | egison ./flat.egi -- each eos="@@@" 3)
178 | assertEquals "AA AB AC
179 | AD
180 | @@@
181 | BA BB BC
182 | BD" "${result}"
183 |
184 | # result=$(printf "AA AB AC AD\nBA BB BC BD" | egison ./flat.egi -- each eos='\' 3)
185 | # assertEquals 'AA AB AC
186 | # AD
187 | # \
188 | # BA BB BC
189 | # BD' "${result}"
190 | }
191 |
192 | test_slit() {
193 | result=$(seq 10 | egison ./slit.egi)
194 | assertEquals "1
195 | 2
196 | 3
197 | 4
198 | 5
199 | 6
200 | 7
201 | 8
202 | 9
203 | 10" "${result}"
204 |
205 | result=$(seq 10 | egison ./slit.egi -- 4)
206 | assertEquals "1 2 3
207 | 4 5 6
208 | 7 8
209 | 9 10" "${result}"
210 |
211 | result=$(seq 10 | egison ./slit.egi -- ofs="-" 5)
212 | assertEquals "1-2
213 | 3-4
214 | 5-6
215 | 7-8
216 | 9-10" "${result}"
217 |
218 | result=$(seq 10 | egison ./flat.egi -- ofs="@" | egison ./slit.egi fs="@" 2)
219 | assertEquals "1@2@3@4@5
220 | 6@7@8@9@10" "${result}"
221 |
222 | result=$(printf "AA AB AC AD\nBA BB BC BD" | egison ./slit.egi -- 3)
223 | assertEquals "AA AB AC
224 | AD BA BB
225 | BC BD" "${result}"
226 |
227 | result=$(printf "AA AB AC AD AE\nBA BB BC BD BE" | egison ./slit.egi -- each 2)
228 | assertEquals "AA AB AC
229 | AD AE
230 | BA BB BC
231 | BD BE" "${result}"
232 |
233 | result=$(echo "AA AB AC AD" | egison ./slit.egi -- 3)
234 | assertEquals "AA AB
235 | AC
236 | AD" "${result}"
237 |
238 | result=$(printf "AA AB AC AD AE\nBA BB BC BD BE" | egison ./slit.egi -- each 4)
239 | assertEquals "AA AB
240 | AC
241 | AD
242 | AE
243 | BA BB
244 | BC
245 | BD
246 | BE" "${result}"
247 |
248 | result=$(printf "AA AB AC AD\nBA BB BC BD" | egison ./slit.egi -- each eos="@@@" 3)
249 | assertEquals "AA AB
250 | AC
251 | AD
252 | @@@
253 | BA BB
254 | BC
255 | BD" "${result}"
256 |
257 | }
258 |
259 | test_crops() {
260 | result=$(echo "(* (cos α) (cos β))" | egison ./crops.egi -- "\(.*\)")
261 | assertEquals "(* (cos α)
262 | (cos α)
263 | (* (cos α) (cos β)
264 | (cos α) (cos β)
265 | (cos β)
266 | (* (cos α) (cos β))
267 | (cos α) (cos β))
268 | (cos β))" "${result}"
269 | }
270 |
271 | test_cycle() {
272 | result=$(echo A B C D E | egison ./cycle.egi)
273 | assertEquals "A B C D E
274 | B C D E A
275 | C D E A B
276 | D E A B C
277 | E A B C D" "${result}"
278 | }
279 |
280 | test_dropl() {
281 | result=$(echo A B C D E F G | egison ./dropl.egi -- 3)
282 | assertEquals "D E F G" "${result}"
283 |
284 | result=$(echo A B C D E F G | egison ./dropl.egi -- ofs=_ 3)
285 | assertEquals "D_E_F_G" "${result}"
286 | }
287 |
288 | test_dropr() {
289 | result=$(echo A B C D E F G | egison ./dropr.egi -- 3)
290 | assertEquals "A B C D" "${result}"
291 |
292 | result=$(echo A B C D E F G | egison ./dropr.egi -- ofs=_ 3)
293 | assertEquals "A_B_C_D" "${result}"
294 | }
295 |
296 | test_dupl() {
297 | result=$(echo A B C D E F G | egison ./dupl.egi -- 3)
298 | assertEquals "A B C D E F G
299 | A B C D E F G
300 | A B C D E F G" "${result}"
301 |
302 | result=$(printf "A B C\nD E F G" | egison ./dupl.egi -- ofs=_ eos=--- 3)
303 | assertEquals "A_B_C
304 | A_B_C
305 | A_B_C
306 | ---
307 | D_E_F_G
308 | D_E_F_G
309 | D_E_F_G" "${result}"
310 | }
311 |
312 | test_mirror() {
313 | result=$(echo AAA BBB CCC AAA | egison ./mirror.egi)
314 | assertEquals "AAA CCC BBB AAA" "${result}"
315 | }
316 |
317 | test_obrev() {
318 | result=$(echo AAA BBB CCC AAA | egison ./obrev.egi)
319 | assertEquals "AAA BBB CCC AAA
320 | AAA CCC BBB AAA" "${result}"
321 |
322 | result=$(printf "1 2 3 4\nA B C D" | egison ./obrev.egi -- eos=---)
323 | assertEquals "1 2 3 4
324 | 4 3 2 1
325 | ---
326 | A B C D
327 | D C B A" "${result}"
328 |
329 | }
330 |
331 | test_nestl() {
332 | result=$(echo AAA BBB CCC | egison ./nestl.egi -- "*
")
333 | assertEquals "
AAA
BBB CCC " "${result}"
334 | }
335 |
336 | test_nestr() {
337 | result=$(echo AAA BBB CCC | egison ./nestr.egi -- "*
")
338 | assertEquals " AAA
BBB
CCC
" "${result}"
339 | }
340 |
341 | test_perm() {
342 | result=$(echo A B C D | egison ./perm.egi -- 2)
343 | assertEquals "A B
344 | A C
345 | B A
346 | A D
347 | B C
348 | C A
349 | B D
350 | C B
351 | D A
352 | C D
353 | D B
354 | D C" "${result}"
355 |
356 | result=$(echo A B C D | egison ./perm.egi -- 100)
357 | assertEquals "A B C D
358 | A B D C
359 | A C B D
360 | B A C D
361 | A C D B
362 | A D B C
363 | B A D C
364 | B C A D
365 | C A B D
366 | A D C B
367 | B C D A
368 | B D A C
369 | C A D B
370 | C B A D
371 | D A B C
372 | B D C A
373 | C B D A
374 | C D A B
375 | D A C B
376 | D B A C
377 | C D B A
378 | D B C A
379 | D C A B
380 | D C B A" "${result}"
381 | }
382 |
383 | test_stairl() {
384 | result=$(echo A B C D | egison ./stairl.egi)
385 | assertEquals "A
386 | A B
387 | A B C
388 | A B C D" "${result}"
389 | }
390 |
391 | test_stairr() {
392 | result=$(echo A B C D | egison ./stairr.egi)
393 | assertEquals "D
394 | C D
395 | B C D
396 | A B C D" "${result}"
397 | }
398 |
399 | test_sublist() {
400 | result=$(echo A B C D | egison ./sublist.egi)
401 | assertEquals "A
402 | A B
403 | B
404 | A B C
405 | B C
406 | C
407 | A B C D
408 | B C D
409 | C D
410 | D" "${result}"
411 | }
412 |
413 | test_subset() {
414 | result=$(echo A B C D | egison ./subset.egi)
415 | assertEquals "A
416 | B
417 | C
418 | D
419 | A B
420 | A C
421 | B C
422 | A D
423 | B D
424 | C D
425 | A B C
426 | A B D
427 | A C D
428 | B C D
429 | A B C D" "${result}"
430 | }
431 |
432 |
433 | test_takel() {
434 | result=$(echo A B C D E F G | egison ./takel.egi -- 3)
435 | assertEquals "A B C" "${result}"
436 |
437 | result=$(echo A B C D E F G | egison ./takel.egi -- 100)
438 | assertEquals "A B C D E F G" "${result}"
439 |
440 | result=$(echo A B C D E F G | egison ./takel.egi -- ofs=_ 3)
441 | assertEquals "A_B_C" "${result}"
442 | }
443 |
444 | test_taker() {
445 | result=$(echo A B C D E F G | egison ./taker.egi -- 3)
446 | assertEquals "E F G" "${result}"
447 |
448 | result=$(echo A B C D E F G | egison ./taker.egi -- 100)
449 | assertEquals "A B C D E F G" "${result}"
450 |
451 | result=$(echo A B C D E F G | egison ./taker.egi -- ofs=_ 3)
452 | assertEquals "E_F_G" "${result}"
453 | }
454 |
455 | test_takelx() {
456 | result=$(echo QBY JCG FCM PAG TPX BQG UGB | egison ./takelx.egi -- "^P.*$")
457 | assertEquals "QBY JCG FCM PAG" "${result}"
458 |
459 | result=$(echo QBY JCG FCM PAG TPX BQG UGB | egison ./takelx.egi -- ofs=_ "^P.*$")
460 | assertEquals "QBY_JCG_FCM_PAG" "${result}"
461 | }
462 |
463 | test_takerx() {
464 | result=$(echo QBY JCG FCM PAG TPX BQG UGB | egison ./takerx.egi -- "^P.*$")
465 | assertEquals "PAG TPX BQG UGB" "${result}"
466 |
467 | result=$(echo QBY JCG FCM PAG TPX BQG UGB | egison ./takerx.egi -- fs=" " ofs="*" "^P.*$")
468 | assertEquals "PAG*TPX*BQG*UGB" "${result}"
469 | }
470 |
471 | test_wrap() {
472 | result=$(echo aaa bbb ccc | egison ./wrap.egi -- "*
")
473 | assertEquals "aaa
bbb
ccc
" "${result}"
474 |
475 | result=$(echo aaa bbb ccc | egison ./wrap.egi -- ofs=_ "*
")
476 | assertEquals "aaa
_bbb
_ccc
" "${result}"
477 | }
478 |
479 | test_zniq() {
480 | result=$(echo aaa bbb ccc aaa bbb | egison ./zniq.egi)
481 | assertEquals "aaa bbb ccc" "${result}"
482 |
483 | result=$(echo aaa bbb ccc aaa bbb | egison ./zniq.egi -- ofs="*")
484 | assertEquals "aaa*bbb*ccc" "${result}"
485 | }
486 |
487 | test_zrep() {
488 | result=$(echo 1 2 3 4 5 6 7 8 9 10 | egison ./zrep.egi -- "1")
489 | assertEquals "1 10" "${result}"
490 |
491 | result=$(echo 1 2 3 4 5 6 7 8 9 10 | egison ./zrep.egi -- 1)
492 | assertEquals "1 10" "${result}"
493 |
494 | result=$(echo AD1 AD2 AF1 AF2 BD1 BD2 BF1 BF2 CD1 CD2 CF1 CF2 DD1 DD2 DF1 DF2 | egison ./zrep.egi -- '^D.*$')
495 | assertEquals "DD1 DD2 DF1 DF2" "${result}"
496 |
497 | result=$(echo AD1 AD2 AF1 AF2 BD1 BD2 BF1 BF2 CD1 CD2 CF1 CF2 DD1 DD2 DF1 DF2 | egison ./zrep.egi -- 'あ')
498 | assertEquals "" "${result}"
499 | }
500 |
501 | # shellcheck source=/dev/null
502 | . "${TEST_DIR}/shunit2/source/2.1/src/shunit2"
503 |
--------------------------------------------------------------------------------
/test/lib/filters.egi:
--------------------------------------------------------------------------------
1 | --
2 | -- This file has been auto-generated by egison-translator.
3 | --
4 |
5 | loadFile "./lib/egzact/filters.egi"
6 |
7 | assertEqual
8 | (debug "plain")
9 | (filterPlain "" ["a", "b", "c", "d"])
10 | [["a", "b", "c", "d"]]
11 |
12 | assertEqual
13 | (debug "addl")
14 | (filterAddl "A" ["a", "b", "c", "d"])
15 | [["A", "a", "b", "c", "d"]]
16 |
17 | assertEqual
18 | (debug "addr")
19 | (filterAddr "B" ["a", "b", "c", "d"])
20 | [["a", "b", "c", "d", "B"]]
21 |
22 | assertEqual
23 | (debug "crops")
24 | (filterCrops "1.*1" ["1", "1", "1", "0", "1", "0", "0", "1", "1", "0"])
25 | [ ["11"]
26 | , ["111"]
27 | , ["11101"]
28 | , ["1101"]
29 | , ["101"]
30 | , ["11101001"]
31 | , ["1101001"]
32 | , ["101001"]
33 | , ["1001"]
34 | , ["111010011"]
35 | , ["11010011"]
36 | , ["1010011"]
37 | , ["10011"] ]
38 |
39 | assertEqual
40 | (debug "cycle")
41 | (filterCycle "" ["a", "b", "c", "d"])
42 | [ ["a", "b", "c", "d"]
43 | , ["b", "c", "d", "a"]
44 | , ["c", "d", "a", "b"]
45 | , ["d", "a", "b", "c"] ]
46 |
47 | assertEqual
48 | (debug "comb")
49 | (filterComb 2 ["a", "b", "c", "d"])
50 | [["a", "b"], ["a", "c"], ["b", "c"], ["a", "d"], ["b", "d"], ["c", "d"]]
51 |
52 | assertEqual
53 | (debug "conv")
54 | (filterConv 2 ["a", "b", "c", "d"])
55 | [["a", "b"], ["b", "c"], ["c", "d"]]
56 |
57 | assertEqual
58 | (debug "conv-each")
59 | (filterConvEach 5 ["a", "b", "c", "d"])
60 | [["a", "b", "c", "d"]]
61 |
62 | assertEqual
63 | (debug "dupl")
64 | (filterDupl 3 ["a", "b", "c", "d"])
65 | [["a", "b", "c", "d"], ["a", "b", "c", "d"], ["a", "b", "c", "d"]]
66 |
67 | assertEqual
68 | (debug "flat")
69 | (filterFlat 3 ["a", "b", "c", "d", "e", "f", "g"])
70 | [["a", "b", "c"], ["d", "e", "f"], ["g"]]
71 |
72 | assertEqual
73 | (debug "perm")
74 | (filterPerm 2 ["a", "b", "c", "d"])
75 | [ ["a", "b"]
76 | , ["a", "c"]
77 | , ["b", "a"]
78 | , ["a", "d"]
79 | , ["b", "c"]
80 | , ["c", "a"]
81 | , ["b", "d"]
82 | , ["c", "b"]
83 | , ["d", "a"]
84 | , ["c", "d"]
85 | , ["d", "b"]
86 | , ["d", "c"] ]
87 |
88 | assertEqual
89 | (debug "stairl")
90 | (filterStairl [] ["a", "b", "c", "d"])
91 | [["a"], ["a", "b"], ["a", "b", "c"], ["a", "b", "c", "d"]]
92 |
93 | assertEqual
94 | (debug "stairr")
95 | (filterStairr [] ["a", "b", "c", "d"])
96 | [["d"], ["c", "d"], ["b", "c", "d"], ["a", "b", "c", "d"]]
97 |
98 | assertEqual
99 | (debug "sublist")
100 | (filterSublist [] ["a", "b", "c", "d"])
101 | [ ["a"]
102 | , ["a", "b"]
103 | , ["b"]
104 | , ["a", "b", "c"]
105 | , ["b", "c"]
106 | , ["c"]
107 | , ["a", "b", "c", "d"]
108 | , ["b", "c", "d"]
109 | , ["c", "d"]
110 | , ["d"] ]
111 |
112 | assertEqual
113 | (debug "subset")
114 | (filterSubset [] ["a", "b", "c", "d"])
115 | [ ["a"]
116 | , ["b"]
117 | , ["c"]
118 | , ["d"]
119 | , ["a", "b"]
120 | , ["a", "c"]
121 | , ["b", "c"]
122 | , ["a", "d"]
123 | , ["b", "d"]
124 | , ["c", "d"]
125 | , ["a", "b", "c"]
126 | , ["a", "b", "d"]
127 | , ["a", "c", "d"]
128 | , ["b", "c", "d"]
129 | , ["a", "b", "c", "d"] ]
130 |
131 | assertEqual
132 | (debug "takel")
133 | (filterTakel 4 ["aba", "bab", "cbc", "afe", "g4a", "gda", "bbf", "cac"])
134 | [["aba", "bab", "cbc", "afe"]]
135 |
136 | assertEqual
137 | (debug "taker")
138 | (filterTaker 4 ["aba", "bab", "cbc", "afe", "g4a", "gda", "bbf", "cac"])
139 | [["g4a", "gda", "bbf", "cac"]]
140 |
141 | assertEqual
142 | (debug "takelx -- case 1")
143 | (filterTakelx "c.c" ["aba", "bab", "cbc", "afe", "g4a", "gda", "bbf", "cac"])
144 | [["aba", "bab", "cbc"]]
145 |
146 | assertEqual
147 | (debug "takelx -- case 2")
148 | (filterTakelx "h.*" ["aba", "bab", "cbc", "afe", "g4a", "gda", "bbf", "cac"])
149 | [[]]
150 |
151 | assertEqual
152 | (debug "takerx -- case 1")
153 | (filterTakerx "g.a" ["aba", "bab", "cbc", "afe", "g4a", "gda", "bbf", "cac"])
154 | [["gda", "bbf", "cac"]]
155 |
156 | assertEqual
157 | (debug "takerx -- case 2")
158 | (filterTakerx "h.*" ["aba", "bab", "cbc", "afe", "g4a", "gda", "bbf", "cac"])
159 | [[]]
160 |
161 | assertEqual
162 | (debug "dropl")
163 | (filterDropl 4 ["aba", "bab", "cbc", "afe", "g4a", "gda", "bbf", "cac"])
164 | [["g4a", "gda", "bbf", "cac"]]
165 |
166 | assertEqual
167 | (debug "dropr")
168 | (filterDropr 4 ["aba", "bab", "cbc", "afe", "g4a", "gda", "bbf", "cac"])
169 | [["aba", "bab", "cbc", "afe"]]
170 |
171 | assertEqual
172 | (debug "zrep -- case 1")
173 | (filterZrep "^1" ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"])
174 | [["1", "10"]]
175 |
176 | assertEqual
177 | (debug "zrep -- case 2")
178 | (filterZrep "^a$" ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"])
179 | [[]]
180 |
181 | assertEqual
182 | (debug "zrep -- case 3")
183 | (filterZrep "a$" ["aba", "bab", "cbc", "afe", "g4a", "gda", "bbf", "cac"])
184 | [["aba", "g4a", "gda"]]
185 |
186 | assertEqual
187 | (debug "zniq -- case 1")
188 | (filterZniq () ["aaa", "bbb", "ccc", "aaa", "bbb"])
189 | [["aaa", "bbb", "ccc"]]
190 |
191 | assertEqual (debug "zniq -- case 2") (filterZniq () ["aaa"]) [["aaa"]]
192 |
193 | assertEqual
194 | (debug "wrap -- case 1")
195 | (filterWrap "" ["aaa", "bbb", "ccc"])
196 | [["", "", ""]]
197 |
198 | assertEqual
199 | (debug "wrap -- case 2")
200 | (filterWrap "" ["aaa", "bbb", "ccc"])
206 | [ [ ""
211 | , "bbb"
212 | , ""
213 | , "ccc"
214 | , "" ] ]
215 |
216 | assertEqual
217 | (debug "nestr -- case 1")
218 | (filterNestr "" ["aaa", "bbb", "ccc"])
219 | [ [ ""
226 | , ""
227 | , "" ] ]
228 |
229 | assertEqual
230 | (debug "mirror")
231 | (filterMirror () ["a", "b", "c", "d"])
232 | [["d", "c", "b", "a"]]
233 |
234 | assertEqual
235 | (debug "obrev")
236 | (filterObrev () ["a", "b", "c", "d"])
237 | [["a", "b", "c", "d"], ["d", "c", "b", "a"]]
238 |
239 | assertEqual
240 | (debug "equalized-partition-nums -- case 1")
241 | (equalizedPartitionNums 100 6)
242 | [17, 17, 17, 17, 16, 16]
243 |
244 | assertEqual
245 | (debug "equalized-partition-nums -- case 2")
246 | (equalizedPartitionNums 100 10)
247 | [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
248 |
249 | assertEqual
250 | (debug "equalized-partition-nums -- case 3")
251 | (equalizedPartitionNums 3 6)
252 | [1, 1, 1, 0, 0, 0]
253 |
254 | assertEqual
255 | (debug "filter-slit -- case 1")
256 | (filterSlit 4 ["A", "B", "C", "D", "E", "F", "G", "H", "I"])
257 | [["A", "B", "C"], ["D", "E"], ["F", "G"], ["H", "I"]]
258 |
259 | assertEqual
260 | (debug "filter-slit -- case 2")
261 | (filterSlit 2 ["a", "b", "c", "d", "e", "f", "g"])
262 | [["a", "b", "c", "d"], ["e", "f", "g"]]
263 |
264 | assertEqual
265 | (debug "filter-slit -- case 3")
266 | (filterSlit 3 ["a", "b", "c", "d", "e", "f", "g"])
267 | [["a", "b", "c"], ["d", "e"], ["f", "g"]]
268 |
--------------------------------------------------------------------------------
/test/lib/utils.egi:
--------------------------------------------------------------------------------
1 | --
2 | -- This file has been auto-generated by egison-translator.
3 | --
4 |
5 | loadFile "./lib/egzact/utils.egi"
6 |
7 | assertEqual
8 | (debug "check-opts -- case 1")
9 | (checkOpts ["A=B", "B=3", "C=143"])
10 | True
11 |
12 | assertEqual
13 | (debug "check-opts -- case 2")
14 | (checkOpts ["A=B", "B=3", "143"])
15 | False
16 |
17 | assertEqual (debug "check-opts -- case 3") (checkOpts ["fs=\n"]) True
18 |
19 | assertEqual (debug "check-opts -- case 4") (checkOpts []) True
20 |
21 | assertEqual (debug "check-opts -- case 5") (checkOpts ["A"]) False
22 |
23 | assertEqual (debug "num-validation -- case 1") (numValidation 5) 5
24 |
25 | assertEqual (debug "num-validation -- case 2") (numValidation 0) ARGMAX
26 |
27 | assertEqual
28 | (debug "num-validation -- case 3")
29 | (numValidation 100000000000)
30 | ARGMAX
31 |
32 | assertEqual (debug "num-validation -- case 4") (numValidation (-1)) ARGMAX
33 |
34 | assertEqual (debug "num-validation -- case 5") (numValidation ()) ARGMAX
35 |
36 | assertEqual (debug "num-validation -- case 6") (numValidation "10") 10
37 |
38 | assertEqual
39 | (debug "num-validation -- case 7")
40 | (numValidation "10000000000")
41 | ARGMAX
42 |
43 | assertEqual (debug "S.isNats -- case 1") (S.isNats "100000000") True
44 |
45 | assertEqual (debug "S.isNats -- case 2") (S.isNats "1a") False
46 |
47 | assertEqual (debug "S.isNats -- case 3") (S.isNats "02") False
48 |
49 | assertEqual (debug "S.isNats -- case 4") (S.isNats "1") True
50 |
51 | assertEqual (debug "num-validation -- case 8") (numValidation y) ARGMAX
52 |
53 | assertEqual
54 | (debug "join-string -- case 1")
55 | (joinString "," ["a", "b", "c"])
56 | "a,b,c"
57 |
58 | assertEqual (debug "join-string -- case 2") (joinString "," ["a"]) "a"
59 |
60 | assertEqual (debug "join-string -- case 3") (joinString "," []) ""
61 |
62 | assertEqual
63 | (debug "split-whole-input")
64 | (splitWholeInput " " ["a b c", "1 2 3 4"])
65 | ["a", "b", "c", "1", "2", "3", "4"]
66 |
67 | assertEqual
68 | (debug "split-each-line -- case 1")
69 | (splitEachLine " " ["a b c", "1 2 3"])
70 | [["a", "b", "c"], ["1", "2", "3"]]
71 |
72 | assertEqual
73 | (debug "split-each-line -- case 2")
74 | (splitEachLine "" ["ab bc", "12 3"])
75 | [["a", "b", " ", "b", "c"], ["1", "2", " ", "3"]]
76 |
77 | assertEqual
78 | (debug "opts2hash -- case 1")
79 | ((opts2hash ["P1=A", "P2=B"]) "P1")
80 | "A"
81 |
82 | assertEqual (debug "opts2hash -- case 2") ((opts2hash ["P1=A", "P2="]) "P2") ""
83 |
84 | assertEqual
85 | (debug "twocol2string -- case 1")
86 | (twocol2string "-" "@" [["a", "b", "c"], ["d", "e", "f"], ["g"]])
87 | "a-b-c@d-e-f@g"
88 |
89 | assertEqual
90 | (debug "twocol2string -- case 2")
91 | (twocol2string "-" "@" [[], []])
92 | "@"
93 |
94 | assertEqual
95 | (debug "twocol2string -- case 3")
96 | (twocol2string "-" "@" [[], [], []])
97 | "@@"
98 |
99 | assertEqual (debug "twocol2string -- case 4") (twocol2string "-" "@" []) ""
100 |
101 | assertEqual
102 | (debug "escape-chars")
103 | ((escapeChars 'a') ['a', 'b', 'c', 'a', 'b', 'd'])
104 | ['\\', 'a', 'b', 'c', '\\', 'a', 'b', 'd']
105 |
106 | assertEqual
107 | (debug "set-default-opts -- case 1")
108 | (setDefaultOpts
109 | (\match as something with
110 | | #"eof" -> "AAA"
111 | | #"ifs" -> "BBB"
112 | | #"eos" -> "---"
113 | | _ -> []))
114 | ("BBB", " ", "\n", "\n---\n", "AAA")
115 |
116 | assertEqual
117 | (debug "set-default-opts -- case 2")
118 | (setDefaultOpts
119 | (\match as something with
120 | | #"dummy" -> "1"
121 | | _ -> []))
122 | (" ", " ", "\n", "\n", "\n")
123 |
124 | assertEqual
125 | (debug "set-default-value -- case 1")
126 | (setDefaultValue ["A", "B", "C"])
127 | "A"
128 |
129 | assertEqual
130 | (debug "set-default-value -- case 2")
131 | (setDefaultValue [(), "B", "C"])
132 | "B"
133 |
134 | assertEqual
135 | (debug "set-default-value -- case 3")
136 | (setDefaultValue [(), (), "C"])
137 | "C"
138 |
139 | assertEqual
140 | (debug "set-default-value -- case 4")
141 | (setDefaultValue ["A", (), "C"])
142 | "A"
143 |
144 | assertEqual
145 | (debug "set-default-value2 -- case 1")
146 | (setDefaultValue2 [(), "C"])
147 | "C"
148 |
149 | assertEqual
150 | (debug "set-default-value2 -- case 2")
151 | (setDefaultValue2 ["A", "B"])
152 | "\nA\n"
153 |
154 | assertEqual
155 | (debug "set-default-value2 -- case 3")
156 | (setDefaultValue2 ["A"])
157 | "\nA\n"
158 |
159 | assertEqual
160 | (debug "S.split2 -- case 1")
161 | (S.split2 " " "a b c")
162 | (S.split " " "a b c")
163 |
164 | assertEqual
165 | (debug "S.split2 -- case 2")
166 | (S.split2 "" "a b c")
167 | ["a", " ", "b", " ", "c"]
168 |
169 | assertEqual
170 | (debug "intersperse2")
171 | (intersperse2 "---" ["a b c", "1 2 3", "e f g"])
172 | ["a b c", "---", "1 2 3", "---", "e f g"]
173 |
--------------------------------------------------------------------------------