Ruby GTK3移行後のメインリポジトリ
修訂 | 5c96eaff0a7378d578cd515ec6c1336eaedf7ce6 (tree) |
---|---|
時間 | 2016-12-11 15:08:05 |
作者 | Shyouzou Sugitani <shy@user...> |
Commiter | Shyouzou Sugitani |
coding style cleanup and misc fixes
@@ -1,3 +1,7 @@ | ||
1 | +Sun December 11 2016 Shyouzou Sugitani <shy@users.osdn.me> | |
2 | + * Rubyらしいコーディングスタイルへの修正. | |
3 | + * Makotoクラスのテストをtest-makoto.rbに移動. | |
4 | + | |
1 | 5 | Thu October 20 2016 Shyouzou Sugitani <shy@users.osdn.me> |
2 | 6 | * deprecatedになっているGtkのWidgetを使用しないようにした. |
3 | 7 | (Gtk::ActionGroupとGtk::UIManagerの2つ.) |
@@ -25,15 +25,15 @@ module Home | ||
25 | 25 | end |
26 | 26 | |
27 | 27 | def self.get_archive_dir() |
28 | - File.join(get_ninix_home(), 'archive') | |
28 | + File.join(get_ninix_home, 'archive') | |
29 | 29 | end |
30 | 30 | |
31 | 31 | def self.get_pango_fontrc() |
32 | - File.join(get_ninix_home(), 'pango_fontrc') | |
32 | + File.join(get_ninix_home, 'pango_fontrc') | |
33 | 33 | end |
34 | 34 | |
35 | 35 | def self.get_preferences() |
36 | - File.join(get_ninix_home(), 'preferences') | |
36 | + File.join(get_ninix_home, 'preferences') | |
37 | 37 | end |
38 | 38 | |
39 | 39 | def self.get_normalized_path(path) |
@@ -46,18 +46,18 @@ module Home | ||
46 | 46 | |
47 | 47 | def self.load_config() |
48 | 48 | return nil unless File.exists?(get_ninix_home()) |
49 | - ghosts = search_ghosts() | |
50 | - balloons = search_balloons() | |
51 | - nekoninni = search_nekoninni() | |
52 | - katochan = search_katochan() | |
53 | - kinoko = search_kinoko() | |
49 | + ghosts = search_ghosts | |
50 | + balloons = search_balloons | |
51 | + nekoninni = search_nekoninni | |
52 | + katochan = search_katochan | |
53 | + kinoko = search_kinoko | |
54 | 54 | return ghosts, balloons, nekoninni, katochan, kinoko |
55 | 55 | end |
56 | 56 | |
57 | 57 | def self.get_shiori() |
58 | 58 | table = {} |
59 | 59 | shiori_lib = DLL::Library.new('shiori', :saori_lib => nil) |
60 | - path = DLL.get_path() | |
60 | + path = DLL.get_path | |
61 | 61 | Dir.foreach(path, :encoding => 'UTF-8') do |filename| |
62 | 62 | next if filename == '..' or filename == '.' |
63 | 63 | if File.readable_real?(File.join(path, filename)) |
@@ -68,9 +68,7 @@ module Home | ||
68 | 68 | name = basename if ['.rb'].include?(ext) |
69 | 69 | unless name.nil? or table.include?(name) |
70 | 70 | shiori = shiori_lib.request(['', name]) |
71 | - unless shiori.nil? | |
72 | - table[name] = shiori | |
73 | - end | |
71 | + table[name] = shiori unless shiori.nil? | |
74 | 72 | end |
75 | 73 | end |
76 | 74 | end |
@@ -21,7 +21,7 @@ module Makoto | ||
21 | 21 | i, text = expand(s, i) |
22 | 22 | buf << text |
23 | 23 | end |
24 | - return buf.join | |
24 | + buf.join | |
25 | 25 | end |
26 | 26 | |
27 | 27 | def self.expand(s, start) |
@@ -67,55 +67,17 @@ module Makoto | ||
67 | 67 | i += 1 |
68 | 68 | end |
69 | 69 | end |
70 | - if validity == 2 | |
70 | + case validity | |
71 | + when 2 | |
71 | 72 | expanded = segments[1..segments.length-1].sample |
72 | 73 | unless repeat_count.nil? |
73 | 74 | expanded = (expanded * rand(repeat_count)) |
74 | 75 | end |
75 | 76 | return i, segments[0] + expanded |
76 | - elsif validity.zero? | |
77 | + when 0 | |
77 | 78 | return j, buf.join |
78 | 79 | else |
79 | 80 | return j, s[start..s.length-1] |
80 | 81 | end |
81 | 82 | end |
82 | - | |
83 | - def self.test(verbose: 0) | |
84 | - for test, expected in [['a(1)b', ['a1b']], | |
85 | - ['a(1|2)b', ['a1b', 'a2b']], | |
86 | - ['a(1)2b', ['ab', 'a1b', 'a11b']], | |
87 | - ['a(1|2)1b', ['ab', 'a1b', 'a2b']], | |
88 | - ['(1|2)(a|b)', ['1a', '1b', '2a', '2b']], | |
89 | - ['((1|2)|(a|b))', ['1', '2', 'a', 'b']], | |
90 | - ['()', ['']], | |
91 | - ['()2', ['']], | |
92 | - ['a()b', ['ab']], | |
93 | - ['a()2b', ['ab']], | |
94 | - ['a\(1\|2\)b', ['a(1|2)b']], | |
95 | - ['\((1|2)\)', ['(1)', '(2)']], | |
96 | - ['\(1)', ['(1)']], | |
97 | - ['a|b', ['a|b']], | |
98 | - # errornous cases | |
99 | - ['(1', ['(1']], | |
100 | - ['(1\)', ['(1\)']], | |
101 | - ['(1|2', ['(1|2']], | |
102 | - ['(1|2\)', ['(1|2\)']], | |
103 | - ['(1|2)(a|b', ['1(a|b', '2(a|b']], | |
104 | - ['((1|2)|(a|b)', ['((1|2)|(a|b)']], | |
105 | - ] | |
106 | - result = execute(test) | |
107 | - print("'", test.to_s, "'", ' => ', "'", result.to_s, "'", ' ... ',) unless verbose.zero? | |
108 | - begin | |
109 | - if expected.nil? | |
110 | - fail "assert" unless result == test | |
111 | - else | |
112 | - fail "assert" unless expected.include?(result) | |
113 | - end | |
114 | - print("OK\n") unless verbose.zero? | |
115 | - rescue #AssertionError | |
116 | - print("NG\n") unless verbose.zero? | |
117 | - raise | |
118 | - end | |
119 | - end | |
120 | - end | |
121 | 83 | end |
@@ -7,9 +7,48 @@ module NinixTest | ||
7 | 7 | def initialize |
8 | 8 | print("testing...\n") |
9 | 9 | for i in 0...1000 |
10 | - Makoto.test() | |
10 | + do_test() | |
11 | + end | |
12 | + do_test(:verbose => 1) | |
13 | + end | |
14 | + | |
15 | + def do_test(verbose: 0) | |
16 | + for test, expected in [['a(1)b', ['a1b']], | |
17 | + ['a(1|2)b', ['a1b', 'a2b']], | |
18 | + ['a(1)2b', ['ab', 'a1b', 'a11b']], | |
19 | + ['a(1|2)1b', ['ab', 'a1b', 'a2b']], | |
20 | + ['(1|2)(a|b)', ['1a', '1b', '2a', '2b']], | |
21 | + ['((1|2)|(a|b))', ['1', '2', 'a', 'b']], | |
22 | + ['()', ['']], | |
23 | + ['()2', ['']], | |
24 | + ['a()b', ['ab']], | |
25 | + ['a()2b', ['ab']], | |
26 | + ['a\(1\|2\)b', ['a(1|2)b']], | |
27 | + ['\((1|2)\)', ['(1)', '(2)']], | |
28 | + ['\(1)', ['(1)']], | |
29 | + ['a|b', ['a|b']], | |
30 | + # errornous cases | |
31 | + ['(1', ['(1']], | |
32 | + ['(1\)', ['(1\)']], | |
33 | + ['(1|2', ['(1|2']], | |
34 | + ['(1|2\)', ['(1|2\)']], | |
35 | + ['(1|2)(a|b', ['1(a|b', '2(a|b']], | |
36 | + ['((1|2)|(a|b)', ['((1|2)|(a|b)']], | |
37 | + ] | |
38 | + result = Makoto.execute(test) | |
39 | + print("'", test.to_s, "'", ' => ', "'", result.to_s, "'", ' ... ',) unless verbose.zero? | |
40 | + begin | |
41 | + if expected.nil? | |
42 | + fail "assert" unless result == test | |
43 | + else | |
44 | + fail "assert" unless expected.include?(result) | |
45 | + end | |
46 | + print("OK\n") unless verbose.zero? | |
47 | + rescue #AssertionError | |
48 | + print("NG\n") unless verbose.zero? | |
49 | + raise | |
50 | + end | |
11 | 51 | end |
12 | - Makoto.test(:verbose => 1) | |
13 | 52 | end |
14 | 53 | end |
15 | 54 | end |