Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

pkg-0.0.2追加

  • Loading branch information...
commit 3e2edd6788721bdd0cd47ede84f88710060551de 1 parent e03848b
@masui authored
View
BIN  pkg/re_expand-0.0.2.gem
Binary file not shown
View
0  pkg/re_expand-0.0.2/.gemtest
No changes.
View
4 pkg/re_expand-0.0.2/History.txt
@@ -0,0 +1,4 @@
+=== 0.0.1 2012-04-30
+
+* 1 major enhancement:
+ * Initial release
View
20 pkg/re_expand-0.0.2/Manifest.txt
@@ -0,0 +1,20 @@
+History.txt
+Manifest.txt
+PostInstall.txt
+README.rdoc
+Rakefile
+lib/re_expand.rb
+lib/Generator.rb
+lib/Node.rb
+lib/Asearch.rb
+lib/Scanner.rb
+script/console
+script/destroy
+script/generate
+test/test_helper.rb
+test/test_re_expand.rb
+test/test_asearch.rb
+test/test_generator.rb
+test/test_re_expand.rb
+test/test_scanner.rb
+
View
7 pkg/re_expand-0.0.2/PostInstall.txt
@@ -0,0 +1,7 @@
+
+For more information on re_expand, see http://re_expand.rubyforge.org
+
+NOTE: Change this information in PostInstall.txt
+You can also delete it if you don't want it.
+
+
View
43 pkg/re_expand-0.0.2/README.rdoc
@@ -0,0 +1,43 @@
+= re_expand
+
+* http://github.com/masui/expand-ruby
+
+== DESCRIPTION:
+
+Generates all the text strings which match the given regexp.
+If a filter pattern is given, the output is filtered by the pattern.
+
+== SYNOPSIS:
+
+ require 're_expand'
+ "test (a|b|c)".expand { |s|
+ puts s
+ }
+ # "test a", "test b", ...
+ "(a|b)(1|2)".expand
+ # => ['a1', 'a2', 'b1', 'b2']
+
+== LICENSE:
+
+(The MIT License)
+
+Copyright (c) 2012 Toshiyuki Masui
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
26 pkg/re_expand-0.0.2/Rakefile
@@ -0,0 +1,26 @@
+require 'rubygems'
+gem 'hoe', '>= 2.1.0'
+require 'hoe'
+require 'fileutils'
+require './lib/re_expand'
+
+Hoe.plugin :newgem
+# Hoe.plugin :website
+# Hoe.plugin :cucumberfeatures
+
+# Generate all the Rake tasks
+# Run 'rake -T' to see list of generated tasks (from gem root directory)
+$hoe = Hoe.spec 're_expand' do
+ self.developer 'Toshiyuki Masui', 'masui@pitecan.com'
+ self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
+ self.rubyforge_name = self.name # TODO this is default value
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
+
+end
+
+require 'newgem/tasks'
+Dir['tasks/**/*.rake'].each { |t| load t }
+
+# TODO - want other tests/tasks run by default? Add them to the list
+# remove_task :default
+# task :default => [:spec, :features]
View
105 pkg/re_expand-0.0.2/lib/Asearch.rb
@@ -0,0 +1,105 @@
+# -*- coding: utf-8 -*-
+# Asearch.rb
+#
+# Created by Toshiyuki Masui on 11/04/16.
+# Copyright 2011 Pitecan Systems. All rights reserved.
+#
+# a = Asearch.new('abcde')
+# a.match('abcde') => true
+# a.match('abXcde',1) => true
+#
+# a = Asearch.new('abcde')
+# initstate = a.initstate
+# laststate = a.state(initstate,'abcde')
+# laststate[0] & a.acceptpat => non-zero value
+#
+
+class Asearch
+ INITPAT = 0x80000000
+ MAXCHAR = 0x100
+
+ def isupper(c)
+ c >= 0x41 && c <= 0x5a
+ end
+
+ def islower(c)
+ c >= 0x61 && c <= 0x7a
+ end
+
+ def tolower(c)
+ c + 0x20
+ end
+
+ def toupper(c)
+ c - 0x20
+ end
+
+ def initialize(pat)
+ @shiftpat = []
+ @epsilon = 0
+ @acceptpat = 0
+ mask = INITPAT
+ (0...MAXCHAR).each { |c|
+ @shiftpat[c] = 0
+ }
+ chars = pat.unpack("C*")
+ chars.each { |c|
+ if c == 0x20 then
+ @epsilon |= mask
+ else
+ @shiftpat[c] |= mask
+ @shiftpat[toupper(c)] |= mask if islower(c)
+ @shiftpat[tolower(c)] |= mask if isupper(c)
+ mask >>= 1
+ end
+ }
+ @acceptpat = mask
+ end
+
+ attr_reader :acceptpat
+
+def bin(val)
+ s = "00000000000000000000000000000000000000000" + sprintf("%b",val)
+ s[-32,100]
+end
+
+ #
+ # 状態stateからテキストstrを認識したときの状態変化
+ #
+ def state(state=nil,str='')
+ if state.nil? then
+ state = initstate
+ end
+ i0 = state[0]
+ i1 = state[1]
+ i2 = state[2]
+ i3 = state[3]
+ chars = str.unpack("C*")
+ chars.each { |c|
+ mask = @shiftpat[c]
+ i3 = (i3 & @epsilon) | ((i3 & mask) >> 1) | (i2 >> 1) | i2
+ i2 = (i2 & @epsilon) | ((i2 & mask) >> 1) | (i1 >> 1) | i1
+ i1 = (i1 & @epsilon) | ((i1 & mask) >> 1) | (i0 >> 1) | i0
+ i0 = (i0 & @epsilon) | ((i0 & mask) >> 1)
+ i1 |= (i0 >> 1)
+ i2 |= (i1 >> 1)
+ i3 |= (i2 >> 1)
+ }
+#puts bin(i3)
+#puts bin(i2)
+#puts bin(i1)
+#puts bin(i0)
+#puts bin(acceptpat | INITPAT)
+ [i0, i1, i2, i3]
+ end
+
+ def initstate
+ [INITPAT, 0, 0, 0]
+ end
+
+ def match(str, ambig=0)
+ s = state(initstate,str)
+ s[ambig] & acceptpat != 0
+ end
+end
+
View
237 pkg/re_expand-0.0.2/lib/Generator.rb
@@ -0,0 +1,237 @@
+# -*- coding: utf-8 -*-
+# Generator.rb
+# ExpandHelpApp
+#
+# Created by Toshiyuki Masui on 2011/02/26.
+# Copyright 2011 Pitecan Systems. All rights reserved.
+
+#
+# ( ( ) ) ( ( ) ( ( ) ) ( ) ) | ( ( ) )
+# pars [1]
+# [1,2]
+# [3]
+# [3,4]
+# [3,5]
+
+require 'Scanner'
+require 'Node'
+require 'Asearch'
+
+module ReExpand
+ class GenNode
+ def initialize(id, state=[], s="", substrings=[], accept=false)
+ @id = id
+ @s = s
+ @substrings = substrings
+ @accept = accept
+ @state = state
+ end
+
+ attr :id, true
+ attr :s, true
+ attr :substrings, true
+ attr :accept, true
+ attr :state, true
+ end
+
+ class Generator
+ def initialize(s = nil)
+ @s = (s ? [s] : [])
+ @matchedlist = []
+ @par = 0
+ @commands = []
+ end
+
+ def add(pat,command)
+ @s << pat
+ @commands << command
+ end
+
+ def delete
+ @s.pop
+ @commands.pop
+ end
+
+ #
+ # ルールを解析して状態遷移機械を作成し、patにマッチするもののリストを返す
+ #
+ def generate(pat, app = nil)
+ res = [[],[],[]] # 曖昧度0,1,2のマッチ結果
+ patterns = pat.split.map { |p| p.downcase }
+
+ @asearch = Asearch.new(pat)
+ scanner = Scanner.new(@s.join('|'))
+
+ # HelpDataで指定した状態遷移機械全体を生成
+ # (少し時間がかかる)
+ (startnode, endnode) = regexp(scanner,true) # top level
+
+ #
+ # 状態遷移機械からDepth-Firstで文字列を生成する
+ # n個のノードを経由して生成される状態の集合をlists[n]に入れる
+ # 生成しながらマッチングも計算する
+ #
+ lists = []
+ listed = [{},{},{}]
+ #
+ # 初期状態
+ #
+ list = []
+ list[0] = GenNode.new(startnode.id, @asearch.initstate)
+ lists[0] = list
+ #
+ (0..1000).each { |length|
+ break if app && app.inputPending
+ list = lists[length]
+ newlist = []
+ # puts "#{length} - #{list.length}"
+ list.each { |entry|
+ srcnode = Node.node(entry.id)
+ if list.length * srcnode.trans.length < 10000 then
+ srcnode.trans.each { |trans|
+ ss = entry.substrings.dup
+ srcnode.pars.each { |i|
+ ss[i-1] = ss[i-1].to_s + trans.arg
+ }
+ newstate = @asearch.state(entry.state, trans.str) # 新しいマッチング状態を計算してノードに保存
+ s = entry.s + trans.str
+ acceptno = trans.dest.accept
+ newlist << GenNode.new(trans.dest.id, newstate, s, ss, acceptno)
+ #
+ # この時点で、マッチしているかどうかをstateとacceptpatで判断できる
+ # マッチしてたら出力リストに加える
+ #
+ if acceptno then
+ maxambig = 2
+ (0..maxambig).each { |ambig|
+ if !listed[ambig][s] then
+ if (newstate[ambig] & @asearch.acceptpat) != 0 then # マッチ
+ maxambig = ambig if ambig < maxambig # 曖昧度0でマッチすれば曖昧度1の検索は不要
+ listed[ambig][s] = true
+ sslen = ss.length
+ if sslen > 0 then
+ # patstr = "(.*)\t" * (sslen-1) + "(.*)"
+ patstr = (["(.*)"] * sslen).join("\t")
+ /#{patstr}/ =~ ss.join("\t")
+ end
+ ## next if $1 == $2
+ # 'set date #{$2}' のような記述の$変数にsubstringの値を代入
+ File.open("/tmp/log","a"){ |f|
+ f.puts "#{s}-----" + eval('%('+@commands[acceptno]+')')
+ }
+ res[ambig] << [s, eval('%('+@commands[acceptno]+')')]
+ end
+ end
+ }
+ end
+ }
+ end
+ }
+ break if newlist.length == 0
+ lists << newlist
+ break if res[0].length > 100
+ }
+ [res[0], res[1], res[2]]
+ end
+
+ #
+ # 正規表現をパースして状態遷移機械を作る
+ #
+ private
+ # n1 n2
+ # +-->□.....□--+
+ # start / \ end
+ # □ --->□.....□---> □
+ # \ /
+ # +-->□.....□--+
+ #
+ def regexp(s,toplevel=false) # regcat { '|' regcat }
+ startnode = Node.new
+ endnode = Node.new
+ if toplevel then
+ @pars = []
+ @parno = 0
+ @ruleid = 0
+ end
+ startnode.pars = @pars
+ endnode.pars = @pars
+ (n1, n2) = regcat(s)
+ startnode.addTrans('',n1)
+ if toplevel then
+ n2.accept = @ruleid
+ end
+ n2.addTrans('',endnode)
+ while s.gettoken == '|' && s.nexttoken != '' do
+ if toplevel then
+ @pars = []
+ @parno = 0
+ @ruleid += 1
+ end
+ (n1, n2) = regcat(s)
+ startnode.addTrans('',n1)
+ if toplevel then
+ n2.accept = @ruleid
+ end
+ n2.addTrans('',endnode)
+ end
+ s.ungettoken
+ return [startnode, endnode]
+ end
+
+ def regcat(s) # regfactor { regfactor }
+ (startnode, endnode) = regfactor(s)
+ while s.gettoken !~ /^[\)\]\|]$/ && s.nexttoken != '' do
+ s.ungettoken
+ (n1, n2) = regfactor(s)
+ endnode.addTrans('',n1)
+ endnode = n2
+ end
+ s.ungettoken
+ return [startnode, endnode]
+ end
+
+ def regfactor(s) # regterm [ '?' | '+' | '*' ]
+ (startnode, endnode) = regterm(s)
+ t = s.gettoken
+ if t =~ /^[\?]$/ then
+ startnode.addTrans('',endnode)
+ elsif t =~ /^[\+]$/ then
+ endnode.addTrans('',startnode)
+ elsif t =~ /^[\*]$/ then
+ startnode.addTrans('',endnode)
+ endnode.addTrans('',startnode)
+ else
+ s.ungettoken
+ end
+ return [startnode,endnode]
+ end
+
+ def regterm(s) # '(' regexp ')' | token
+ t = s.gettoken
+ if t == '(' then
+ @parno += 1
+ @pars.push(@parno)
+ (n1, n2) = regexp(s)
+ n1.pars = @pars.dup
+ t = s.gettoken
+ if t == ')' then
+ @pars.pop
+ n2.pars = @pars.dup
+ return [n1, n2]
+ else
+ puts 'missing )'
+ exit
+ end
+ else
+ startnode = Node.new
+ startnode.pars = @pars.dup
+ endnode = Node.new
+ endnode.pars = @pars.dup
+ startnode.addTrans(t,endnode)
+ return [startnode, endnode]
+ end
+ end
+ end
+
+end
+
View
65 pkg/re_expand-0.0.2/lib/Node.rb
@@ -0,0 +1,65 @@
+# -*- coding: utf-8 -*-
+#
+# ノードとノード間遷移
+#
+# (self) pat dest
+# ■ ----------> □
+# ----------> □
+# ----------> □
+#
+
+module ReExpand
+ class Trans
+ def initialize(pat,dest)
+ # pat にマッチしたら dest に遷移
+ @pat = pat
+ @dest = dest
+ end
+
+ attr_reader :pat, :dest
+
+ def str
+ @pat.split(/\t/)[0].to_s
+ end
+
+ def arg
+ if @pat =~ /^(.*)\t(.*)$/ then
+ return $2
+ else
+ return @pat
+ end
+ end
+ end
+
+ class Node
+ @@id = 1
+ @@nodes = {}
+
+ def initialize
+ @accept = nil
+ @trans = []
+ @id = @@id
+ @@nodes[@id] = self
+ @@id += 1
+ @pars = []
+ end
+
+ attr_reader :id
+ attr_reader :trans
+ attr :accept, true
+ attr :pars, true
+
+ def addTrans(pat,dest)
+ t = Trans.new(pat,dest)
+ @trans << t
+ end
+
+ def Node.node(id) # ノードidからノードを取得
+ @@nodes[id.to_i]
+ end
+
+ def Node.nodes
+ @@nodes.values
+ end
+ end
+end
View
61 pkg/re_expand-0.0.2/lib/Scanner.rb
@@ -0,0 +1,61 @@
+# -*- coding: utf-8 -*-
+#
+# 文字列から1トークンずつ取得
+#
+
+$KCODE = 'utf8'
+
+module ReExpand
+ class Scanner
+ def initialize(s)
+ @s = s
+ @a = s.split(//)
+ @p = 0
+ @t = ''
+ @u = ''
+ end
+
+ def gettoken
+ if @u != '' then
+ @t = @u
+ @u = ''
+ return @t
+ end
+ if @p >= @a.length then
+ @t = ''
+ return ''
+ end
+ @t = @a[@p]
+ if @t =~ /^[\(\|\)\*\?\[\]]$/ then
+ @p += 1
+ return @t
+ elsif @t == '\\' then
+ @p += 1
+ @t = @a[@p]
+ @t = "\n" if @t == 'n'
+ @t = "\t" if @t == 't'
+ @p += 1
+ return @t
+ else
+ @p += 1
+ while @p < @a.length && @a[@p] !~ /^[\(\|\)\*\+\?\[\]\\]$/ do
+ @t += @a[@p]
+ @p += 1
+ end
+ return @t
+ end
+ end
+
+ def ungettoken
+ if @u == '' then
+ @u = @t
+ else
+ puts "Can't ungettoken(#{token})"
+ end
+ end
+
+ def nexttoken
+ return @t
+ end
+ end
+end
View
47 pkg/re_expand-0.0.2/lib/re_expand.rb
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+$:.unshift(File.dirname(__FILE__)) unless
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
+
+module ReExpand
+ VERSION = '0.0.2'
+end
+
+require 'Generator'
+require 'Node'
+require 'Asearch'
+require 'Scanner'
+
+class String
+ # ExpandHelp用のライブラリを利用
+ def expand(filterpat=' ')
+ g = ReExpand::Generator.new
+ g.add(self,'')
+ strings = []
+ if filterpat.class == String then
+ matched = g.generate(filterpat)
+ res = matched[0].length > 0 ? matched[0] : matched[1].length > 0 ? matched[1] : matched[2]
+ strings = res.collect { |r|
+ r[0]
+ }
+ elsif
+ matched = g.generate(' ')
+ strings = matched[0].collect { |r|
+ r[0]
+ }
+ if filterpat.class == Regexp then
+ strings = strings.find_all { |s|
+ filterpat.match(s)
+ }
+ end
+ end
+
+ if block_given? then
+ strings.each { |string|
+ yield string
+ }
+ else
+ strings
+ end
+ end
+end
+
View
10 pkg/re_expand-0.0.2/script/console
@@ -0,0 +1,10 @@
+#!/usr/bin/env ruby
+# File: script/console
+irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
+
+libs = " -r irb/completion"
+# Perhaps use a console_lib to store any extra methods I may want available in the cosole
+# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
+libs << " -r #{File.dirname(__FILE__) + '/../lib/re_expand.rb'}"
+puts "Loading re_expand gem"
+exec "#{irb} #{libs} --simple-prompt"
View
14 pkg/re_expand-0.0.2/script/destroy
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+
+begin
+ require 'rubigen'
+rescue LoadError
+ require 'rubygems'
+ require 'rubigen'
+end
+require 'rubigen/scripts/destroy'
+
+ARGV.shift if ['--help', '-h'].include?(ARGV[0])
+RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
+RubiGen::Scripts::Destroy.new.run(ARGV)
View
14 pkg/re_expand-0.0.2/script/generate
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+
+begin
+ require 'rubigen'
+rescue LoadError
+ require 'rubygems'
+ require 'rubigen'
+end
+require 'rubigen/scripts/generate'
+
+ARGV.shift if ['--help', '-h'].include?(ARGV[0])
+RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
+RubiGen::Scripts::Generate.new.run(ARGV)
View
105 pkg/re_expand-0.0.2/test/test_asearch.rb
@@ -0,0 +1,105 @@
+# -*- coding: utf-8 -*-
+
+require 'Asearch'
+
+class AsearchTest < Test::Unit::TestCase
+ def setup
+ end
+
+ def teardown
+ end
+
+ def test_init
+ a = Asearch.new('abc')
+ state = a.initstate
+ assert state[0] != 0
+ assert state[1] == 0
+ assert state[2] == 0
+ end
+
+ def test_match
+ #
+ # 状態を利用せず普通にマッチングを行なうメソッド
+ #
+ a = Asearch.new('abcde')
+ assert a.match('abcde')
+ assert a.match('abcde',1)
+ assert !a.match('abcd')
+ assert a.match('abcd',1)
+ end
+
+ def test_state
+ #
+ # "abcde"にマッチするかテスト
+ #
+ a = Asearch.new('abcde')
+ initstate = a.initstate
+ laststate = a.state(initstate,'abcde')
+ assert((laststate[0] & a.acceptpat) != 0)
+ laststate = a.state(initstate,'abcdf') # 1文字置換
+ assert((laststate[0] & a.acceptpat) == 0)
+ assert((laststate[1] & a.acceptpat) != 0)
+ assert((laststate[2] & a.acceptpat) != 0)
+ laststate = a.state(initstate,'abde') # 1文字欠損
+ assert((laststate[0] & a.acceptpat) == 0)
+ assert((laststate[1] & a.acceptpat) != 0)
+ assert((laststate[2] & a.acceptpat) != 0)
+ laststate = a.state(initstate,'abcfg') # 2文字置換
+ assert((laststate[0] & a.acceptpat) == 0)
+ assert((laststate[1] & a.acceptpat) == 0)
+ assert((laststate[2] & a.acceptpat) != 0)
+ laststate = a.state(initstate,'abe') # 2文字欠損
+ assert((laststate[0] & a.acceptpat) == 0)
+ assert((laststate[1] & a.acceptpat) == 0)
+ assert((laststate[2] & a.acceptpat) != 0)
+ laststate = a.state(initstate,'axbcde') # 1文字追加
+ assert((laststate[0] & a.acceptpat) == 0)
+ assert((laststate[1] & a.acceptpat) != 0)
+ assert((laststate[2] & a.acceptpat) != 0)
+ laststate = a.state(initstate,'axbcyde') # 2文字追加
+ assert((laststate[0] & a.acceptpat) == 0)
+ assert((laststate[1] & a.acceptpat) == 0)
+ assert((laststate[2] & a.acceptpat) != 0)
+ laststate = a.state(initstate,'ABCDF') # 大文字
+ assert((laststate[0] & a.acceptpat) == 0)
+ assert((laststate[1] & a.acceptpat) != 0)
+ assert((laststate[2] & a.acceptpat) != 0)
+
+ #
+ # ワイルドカード
+ #
+ a = Asearch.new(' abc def')
+ initstate = a.initstate
+ laststate = a.state(initstate,'abcdef')
+ assert((laststate[0] & a.acceptpat) != 0)
+ initstate = a.initstate
+ laststate = a.state(initstate,'abcXXXXdef')
+ assert((laststate[0] & a.acceptpat) != 0)
+ initstate = a.initstate
+ laststate = a.state(initstate,'abcXXXXYYY')
+ assert((laststate[0] & a.acceptpat) == 0)
+ initstate = a.initstate
+ laststate = a.state(initstate,'abcXXXXde')
+ assert((laststate[0] & a.acceptpat) == 0)
+ assert((laststate[1] & a.acceptpat) != 0)
+ assert((laststate[2] & a.acceptpat) != 0)
+ initstate = a.initstate
+ laststate = a.state(initstate,'ZZZZZabcdef')
+ assert((laststate[0] & a.acceptpat) != 0)
+
+ #
+ # 漢字
+ #
+ a = Asearch.new('漢字文字列')
+ initstate = a.initstate
+ laststate = a.state(initstate,'漢字文字列')
+ assert((laststate[0] & a.acceptpat) != 0)
+ laststate = a.state(initstate,'漢字文字')
+ assert((laststate[0] & a.acceptpat) == 0)
+ laststate = a.state(initstate,'漢字!文字列')
+ assert((laststate[0] & a.acceptpat) == 0)
+ assert((laststate[1] & a.acceptpat) != 0)
+ end
+
+end
+
View
32 pkg/re_expand-0.0.2/test/test_generator.rb
@@ -0,0 +1,32 @@
+# -*- coding: utf-8 -*-
+
+module ReExpand
+ class GeneratorTest < Test::Unit::TestCase
+ def setup
+ end
+
+ def teardown
+ end
+
+ def test_clock
+ g = Generator.new
+ g.add '(時計|時間|時刻)を(0|1|2|3|4|5|6|7|8|9|10|11|12)時に(セットする|設定する|あわせる)', 'set time #{$2}:00'
+ res = g.generate(' 10 ')
+ assert res[0].member?(['時刻を10時に設定する','set time 10:00'])
+ assert res[0].member?(['時計を10時にセットする','set time 10:00'])
+ assert !res[0].member?(['時計を8時にセットする','set time 8:00'])
+ end
+
+ def test_substring
+ g = Generator.new
+ g.add '(a)bcd(e(fg)h)i(jk)', '#{$1}/#{$2}/#{$3}/#{$4}'
+ res = g.generate(' b ')
+ assert res[0].member?(['abcdefghijk', 'a/efgh/fg/jk'])
+ assert !res[0].member?(['abcdefghijk', 'a/fgh/fg/jk'])
+ g.add '(ab|cd)efg(hij|klm)n', '#{$1}/#{$2}'
+ res = g.generate(' ef ')
+ assert res[0].member?(['abefghijn', 'ab/hij'])
+ assert res[0].member?(['cdefgklmn', 'cd/klm'])
+ end
+ end
+end
View
3  pkg/re_expand-0.0.2/test/test_helper.rb
@@ -0,0 +1,3 @@
+require 'stringio'
+require 'test/unit'
+require File.dirname(__FILE__) + '/../lib/re_expand'
View
11 pkg/re_expand-0.0.2/test/test_re_expand.rb
@@ -0,0 +1,11 @@
+require File.dirname(__FILE__) + '/test_helper.rb'
+
+class TestReExpand < Test::Unit::TestCase
+
+ def setup
+ end
+
+ def test_truth
+ assert true
+ end
+end
View
28 pkg/re_expand-0.0.2/test/test_scanner.rb
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+
+module ReExpand
+ class ScannerTest < Test::Unit::TestCase
+ def setup
+ end
+
+ def teardown
+ end
+
+ def test_1
+ s = Scanner.new('abc*def')
+ assert_equal s.gettoken, 'abc'
+ assert_equal s.gettoken, '*'
+ assert_equal s.gettoken, 'def'
+ end
+
+ def test_2
+ s = Scanner.new("(a\tb|c\td)")
+ assert_equal s.gettoken, "("
+ assert_equal s.gettoken, "a\tb"
+ assert_equal s.gettoken, '|'
+ assert_equal s.gettoken, "c\td"
+ assert_equal s.gettoken, ')'
+ end
+ end
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.