forked from aichaos/rivescript-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_unicode.py
More file actions
100 lines (78 loc) · 3.36 KB
/
Copy pathtest_unicode.py
File metadata and controls
100 lines (78 loc) · 3.36 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import
import re
from rivescript.exceptions import RS_ERR_MATCH
from .config import RiveScriptTestCase
class UnicodeTest(RiveScriptTestCase):
"""UTF-8 Tests."""
def test_unicode(self):
self.new("""
! sub who's = who is
+ äh
- What's the matter?
+ ブラッキー
- エーフィ
+ my favorite game is *
- <set game=<formal>>When did you first start playing <get game>?
+ what is my favorite game
- Wasn't it <get game>?
// Make sure %Previous continues working in UTF-8 mode.
+ knock knock
- Who's there?
+ *
% who is there
- <sentence> who?
+ *
% * who
- Haha! <sentence>!
// And with UTF-8.
+ tëll më ä pöëm
- Thërë öncë wäs ä män nämëd Tïm
+ more
% thërë öncë wäs ä män nämëd tïm
- Whö nëvër qüïtë lëärnëd höw tö swïm
+ more
% whö nëvër qüïtë lëärnëd höw tö swïm
- Hë fëll öff ä döck, änd sänk lïkë ä röck
+ more
% hë fëll öff ä döck änd sänk lïkë ä röck
- Änd thät wäs thë ënd öf hïm.
""", utf8=True)
self.reply("äh", "What's the matter?")
self.reply("ブラッキー", "エーフィ")
self.reply("My favorite game is Pokémon", "When did you first start playing Pokémon?")
self.reply("What is my favorite game?", "Wasn't it Pokémon?")
self.reply("knock knock", "Who's there?")
self.reply("Orange", "Orange who?")
self.reply("banana", "Haha! Banana!")
self.reply("tëll më ä pöëm", "Thërë öncë wäs ä män nämëd Tïm")
self.reply("more", "Whö nëvër qüïtë lëärnëd höw tö swïm")
self.reply("more", "Hë fëll öff ä döck, änd sänk lïkë ä röck")
self.reply("more", "Änd thät wäs thë ënd öf hïm.")
def test_unicode_punctuation(self):
self.new("""
+ hello bot
- Hello human!
""", utf8=True)
self.reply("Hello bot", "Hello human!")
self.reply("Hello, bot", "Hello human!")
self.reply("Hello: bot", "Hello human!")
self.reply("Hello... bot?", "Hello human!")
# Edit the punctuation regexp.
self.rs.unicode_punctuation = re.compile(r'xxx')
self.reply("Hello bot", "Hello human!")
self.reply("Hello, bot!", RS_ERR_MATCH)
def test_unicode_with_optionals(self):
templates = ["({})", "[{}]"] # Test both alternatives and optionals
trigger_text = "überrasch mich|empfiehl mir was|empfehl mir was|was gibts neues für mich|empfehlung"
for template in templates:
test_template = template.format(trigger_text)
self.new("""
+ {}
- recommendation
""".format(test_template), utf8=True)
self.reply("überrasch mich", "recommendation")
self.reply("überrasch", '[ERR: No Reply Matched]')
self.reply("empfiehl mir was", "recommendation")
self.reply("was gibts neues für mich", "recommendation")