File: langscan-test

package info (click to toggle)
gonzui 1.2-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,824 kB
  • ctags: 1,448
  • sloc: ruby: 9,570; sh: 5,684; ansic: 1,334; lex: 1,140; makefile: 466; perl: 205; ml: 131
file content (32 lines) | stat: -rwxr-xr-x 830 bytes parent folder | download
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
#! /usr/bin/env ruby
#
# langscan-test - langscan tester
#
# Copyright (C) 2005 Satoru Takabayashi <satoru@namazu.org> 
#     All rights reserved.
#     This is free software with ABSOLUTELY NO WARRANTY.
#
# You can redistribute it and/or modify it under the terms of 
# the GNU General Public License version 2.
#

require 'langscan'
if ARGV.length != 1
  puts "Usage: langscan-test FILE"
  exit
end

def assert_equal(a, b)
  raise "\"#{a}\" expected but \"#{b}\"" unless a == b
end


file_name = ARGV.shift
content = File.read(file_name)
scanner = LangScan.choose(file_name, content)
scanner = LangScan::Text if scanner.nil?
scanner.scan(content) {|fragment|
  raise "Fragment#type should be Symbol" unless fragment.type.is_a?(Symbol)
  assert_equal(content[fragment.byteno...fragment.end_byteno], fragment.text)
  p fragment
}