forked from kaitai-io/kaitai_struct_tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec_ruby_to_csharp
executable file
·49 lines (38 loc) · 987 Bytes
/
spec_ruby_to_csharp
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
#!/usr/bin/env ruby
s = $stdin.read
raise "Unable to detect source name" unless s =~ /require ['"](.*?)['"]/
src_name = $1
raise "Unable to detect class name" unless s =~ /RSpec\.describe (.*?) do/
class_name = $1
s.gsub!(/^.*it .parses test properly. do\n/m, '')
src_file = '???'
s.gsub!(/^\s*r = (.*?)\.from_file\('src\/(.*?)'\)$/) {
src_file = $2
''
}
s = s[2..-1] if s[0..1] == "\n\n"
# under_score_case => lowerCamelCase
s.gsub!(/\.([a-zA-Z0-9_]+)/) {
arg = $1
w = arg.split(/_/)
w.map! { |x| x.capitalize }
".#{w.join}"
}
s.gsub!(/expect\((.*?)\)\.To eq\(? *(.*?)\)?$/, 'Assert.AreEqual(\1, \2);')
s.gsub!(/^( +)/) { $1 * 2 }
s.gsub!(/^/, ' ')
s.gsub!(/end$/, '}')
puts <<__EOF__
using NUnit.Framework;
namespace Kaitai
{
[TestFixture]
public class Spec#{class_name} : CommonSpec
{
[Test]
public void Test#{class_name}()
{
var r = #{class_name}.FromFile(SourceFile("#{src_file}"));
__EOF__
print s
puts "}"