-
Notifications
You must be signed in to change notification settings - Fork 6
/
telegram_test.exs
58 lines (45 loc) · 1.19 KB
/
telegram_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
defmodule ALF.Examples.TelegramWithComposer.Pipeline do
use ALF.DSL
@components [
composer(:split_to_words),
composer(:create_lines, memo: [])
]
@length_limit 50
def split_to_words(line, nil, _) do
words =
line
|> String.trim()
|> String.split()
{words, nil}
end
def create_lines(word, words, _) do
string_before = Enum.join(words, " ")
string_after = Enum.join(words ++ [word], " ")
cond do
String.length(string_after) == @length_limit ->
{[string_after], []}
String.length(string_after) > @length_limit ->
{[string_before], [word]}
true ->
{[], words ++ [word]}
end
end
end
defmodule ALF.Examples.TelegramWithComposerTest do
use ExUnit.Case, async: true
alias ALF.Examples.TelegramWithComposer.Pipeline
setup do
file_stream = File.stream!("test/examples/telegram_input.txt")
Pipeline.start()
on_exit(&Pipeline.stop/0)
%{file_stream: file_stream}
end
test "process input", %{file_stream: file_stream} do
lines =
file_stream
|> Pipeline.stream()
|> Enum.to_list()
assert Enum.count(lines) > 100
assert String.length(hd(lines)) <= 50
end
end