• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

ninix-aya(git://git.osdn.net/gitroot/ninix-aya/ruby-gtk3.git)のfork


コミットメタ情報

リビジョン5c96eaff0a7378d578cd515ec6c1336eaedf7ce6 (tree)
日時2016-12-11 15:08:05
作者Shyouzou Sugitani <shy@user...>
コミッターShyouzou Sugitani

ログメッセージ

coding style cleanup and misc fixes

変更サマリ

差分

--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
1+Sun December 11 2016 Shyouzou Sugitani <shy@users.osdn.me>
2+ * Rubyらしいコーディングスタイルへの修正.
3+ * Makotoクラスのテストをtest-makoto.rbに移動.
4+
15 Thu October 20 2016 Shyouzou Sugitani <shy@users.osdn.me>
26 * deprecatedになっているGtkのWidgetを使用しないようにした.
37 (Gtk::ActionGroupとGtk::UIManagerの2つ.)
--- a/lib/ninix/home.rb
+++ b/lib/ninix/home.rb
@@ -25,15 +25,15 @@ module Home
2525 end
2626
2727 def self.get_archive_dir()
28- File.join(get_ninix_home(), 'archive')
28+ File.join(get_ninix_home, 'archive')
2929 end
3030
3131 def self.get_pango_fontrc()
32- File.join(get_ninix_home(), 'pango_fontrc')
32+ File.join(get_ninix_home, 'pango_fontrc')
3333 end
3434
3535 def self.get_preferences()
36- File.join(get_ninix_home(), 'preferences')
36+ File.join(get_ninix_home, 'preferences')
3737 end
3838
3939 def self.get_normalized_path(path)
@@ -46,18 +46,18 @@ module Home
4646
4747 def self.load_config()
4848 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
5454 return ghosts, balloons, nekoninni, katochan, kinoko
5555 end
5656
5757 def self.get_shiori()
5858 table = {}
5959 shiori_lib = DLL::Library.new('shiori', :saori_lib => nil)
60- path = DLL.get_path()
60+ path = DLL.get_path
6161 Dir.foreach(path, :encoding => 'UTF-8') do |filename|
6262 next if filename == '..' or filename == '.'
6363 if File.readable_real?(File.join(path, filename))
@@ -68,9 +68,7 @@ module Home
6868 name = basename if ['.rb'].include?(ext)
6969 unless name.nil? or table.include?(name)
7070 shiori = shiori_lib.request(['', name])
71- unless shiori.nil?
72- table[name] = shiori
73- end
71+ table[name] = shiori unless shiori.nil?
7472 end
7573 end
7674 end
--- a/lib/ninix/makoto.rb
+++ b/lib/ninix/makoto.rb
@@ -21,7 +21,7 @@ module Makoto
2121 i, text = expand(s, i)
2222 buf << text
2323 end
24- return buf.join
24+ buf.join
2525 end
2626
2727 def self.expand(s, start)
@@ -67,55 +67,17 @@ module Makoto
6767 i += 1
6868 end
6969 end
70- if validity == 2
70+ case validity
71+ when 2
7172 expanded = segments[1..segments.length-1].sample
7273 unless repeat_count.nil?
7374 expanded = (expanded * rand(repeat_count))
7475 end
7576 return i, segments[0] + expanded
76- elsif validity.zero?
77+ when 0
7778 return j, buf.join
7879 else
7980 return j, s[start..s.length-1]
8081 end
8182 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
12183 end
--- a/test/test-makoto.rb
+++ b/test/test-makoto.rb
@@ -7,9 +7,48 @@ module NinixTest
77 def initialize
88 print("testing...\n")
99 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
1151 end
12- Makoto.test(:verbose => 1)
1352 end
1453 end
1554 end