faccts 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ab5b68cc81737ad2a9de3e64778e6a17f3174e70ef2b361c1deeb8749c6d4ae
4
- data.tar.gz: 2b9568a2176536a7f4121304d8009ba76590f105ca12e7f99eef6c5d12d81fcb
3
+ metadata.gz: 8b28f5b1c0a588470033f32ebf3da1656664582fc306ee39864efa1dbdbff38e
4
+ data.tar.gz: 8ce14d9ed707a87fdbcc09752a5eb9dc6738ccce99d936773d3818a08a9481e2
5
5
  SHA512:
6
- metadata.gz: 664e60d3cd0143b32705fbe1851dd9a5bc8a45b6662cd4b14bc36720e675390cbc1a066d01e61c0032ed456d28567daf4f1faec3c6ca7f94089bcfe76b28ce61
7
- data.tar.gz: 813a429fd451bcaeb540dd2daf36c07a559ba3dc006fc6832be919bfc583497bf5dc9d5561f0c940221b947b183523071147e4998055f4f6a55f7856459be195
6
+ metadata.gz: 1b75b866d6d1f86ecdcb7692860a149711c4d505ece0444ba7818ae44833025f521e327770555610f626f641137e9eca2bee4b594407fad9ddb2e86c5b96e3f6
7
+ data.tar.gz: 25024533c1f42b50e3e0069f886cfdc3275c7e110e8947e0b4f0db2781923c4ff611ee3ccbba0264f7f82e3a0ddacd03b97a511ae19c997b280912fa130610f9
@@ -4,6 +4,9 @@ module Faccts
4
4
  class YAMLTestParser
5
5
  class YAMLTestAssertionParser
6
6
  class AssertionSpecificationParser
7
+ ARGUMENT_WRAPPER_CHAR = "\""
8
+ ARGUMENT_NAME_PLACEHOLDER = "X"
9
+
7
10
  def parse(assertion_name_specification)
8
11
  assertion, remaining_specification = extract_assertion_up_to_first_argument(assertion_name_specification)
9
12
 
@@ -3,8 +3,6 @@
3
3
  module Faccts
4
4
  class YAMLTestParser
5
5
  class YAMLTestAssertionParser
6
- ARGUMENT_WRAPPER_CHAR = "\""
7
- ARGUMENT_NAME_PLACEHOLDER = "X"
8
6
  ASSERTION_NODE_NAME = "assert"
9
7
 
10
8
  def initialize(assertion_specification_parsing_strategy)
@@ -8,20 +8,20 @@ module Faccts
8
8
  ASSERTION_NODE_NAME = "assert"
9
9
 
10
10
  def initialize(test_assertion_parser_strategy)
11
- @parser = StandardYAMLParser.new
11
+ @parser = StandardYAMLToHashParser.new
12
12
  @test_assertion_extractor = TestAssertionExtractor.new(test_assertion_parser_strategy)
13
13
  end
14
14
 
15
15
  def create_tests!(test_specification_yaml)
16
- @test_specification = parser.parse_tests!(test_specification_yaml)
16
+ @test_specification_hash = parser.parse!(test_specification_yaml)
17
17
 
18
18
  validate_specification!
19
19
 
20
- assertions = test_assertions_from_specification
20
+ test_assertions = test_assertions_from_specification
21
21
 
22
- raise NoTestsGivenError if assertions.empty?
22
+ return test_assertions unless test_assertions.empty?
23
23
 
24
- assertions
24
+ raise NoTestsGivenError
25
25
  rescue ::Psych::Exception => e
26
26
  raise InvalidYAMLError, e.message
27
27
  end
@@ -36,39 +36,49 @@ module Faccts
36
36
 
37
37
  class InvalidYAMLError < ::StandardError
38
38
  ERROR_MESSAGE = "Cannot parse acceptance tests file"
39
- ERROR_TEMPLATE = "#{ERROR_MESSAGE} - %s".freeze
40
-
41
- def initialize(parse_failure_message = "")
42
- if parse_failure_message == ""
43
- super(ERROR_MESSAGE)
44
- else
45
- super(ERROR_TEMPLATE % parse_failure_message)
46
- end
39
+ ERROR_TEMPLATE = "#{ERROR_MESSAGE} - '%s'".freeze
40
+
41
+ def initialize(parse_failure_message)
42
+ super(ERROR_TEMPLATE % parse_failure_message)
43
+ end
44
+ end
45
+
46
+ class InvalidAssertionError < ::StandardError
47
+ ERROR_MESSAGE = "Assertions must be scalar values!"
48
+
49
+ def initialize(msg = ERROR_MESSAGE)
50
+ super
47
51
  end
48
52
  end
49
53
 
50
54
  private
51
55
 
52
- attr_reader :parser, :test_specification, :test_assertion_extractor
56
+ attr_reader :parser, :test_specification_hash, :test_assertion_extractor
57
+
58
+ class StandardYAMLToHashParser
59
+ def parse!(yaml)
60
+ YAML.load(yaml)
61
+ end
62
+ end
53
63
 
54
64
  def validate_specification!
55
- raise NoTestsGivenError if test_specification.nil?
56
- raise NoTestsGivenError if tests.nil?
57
- raise NoTestsGivenError unless tests.respond_to? :keys
65
+ raise NoTestsGivenError if test_specification_hash.nil?
66
+ raise NoTestsGivenError if tests_hash.nil?
67
+ raise NoTestsGivenError unless tests_hash.is_a?(Hash)
68
+ end
69
+
70
+ def tests_hash
71
+ test_specification_hash[TEST_SUITE_ROOT_NODE_NAME]
58
72
  end
59
73
 
60
74
  def test_assertions_from_specification
61
75
  all_test_names
62
- .map { |test_name| test_assertion_extractor.from_test_name(tests, test_name) }
76
+ .map { |name| test_assertion_extractor.from_test_name(name, tests_hash) }
63
77
  .compact
64
78
  end
65
79
 
66
80
  def all_test_names
67
- tests.keys
68
- end
69
-
70
- def tests
71
- test_specification[TEST_SUITE_ROOT_NODE_NAME]
81
+ tests_hash.keys
72
82
  end
73
83
 
74
84
  class TestAssertionExtractor
@@ -76,22 +86,20 @@ module Faccts
76
86
  @test_assertion_parser = test_assertion_parser_strategy
77
87
  end
78
88
 
79
- def from_test_name(tests, test_name)
80
- @tests = tests
89
+ def from_test_name(test_name, tests_hash)
90
+ @test_assertion_node = tests_hash[test_name]
81
91
  @test_name = test_name
82
92
 
83
93
  return unless test_contains_assertion?
84
94
  return if assertion_is_empty?
85
95
 
96
+ raise InvalidAssertionError if assertion_is_invalid?
97
+
86
98
  test_assertion_parser.parse(test_node)
87
99
  end
88
100
 
89
101
  def test_contains_assertion?
90
- test_assertion_node.respond_to?(:keys) && test_assertion_node.keys.include?(ASSERTION_NODE_NAME)
91
- end
92
-
93
- def test_assertion_node
94
- tests[test_name]
102
+ test_assertion_node.is_a?(Hash) && test_assertion_node.keys.include?(ASSERTION_NODE_NAME)
95
103
  end
96
104
 
97
105
  def assertion_is_empty?
@@ -103,18 +111,16 @@ module Faccts
103
111
  end
104
112
 
105
113
  def name_from_assertion_node
106
- tests[test_name][ASSERTION_NODE_NAME]
114
+ test_assertion_node[ASSERTION_NODE_NAME]
107
115
  end
108
116
 
109
- private
117
+ def assertion_is_invalid?
118
+ name_from_assertion_node.is_a?(Hash) || name_from_assertion_node.is_a?(Array)
119
+ end
110
120
 
111
- attr_reader :test_assertion_parser, :tests, :test_name
112
- end
121
+ private
113
122
 
114
- class StandardYAMLParser
115
- def parse_tests!(test_specification)
116
- YAML.load(test_specification)
117
- end
123
+ attr_reader :test_assertion_parser, :test_assertion_node, :test_name
118
124
  end
119
125
  end
120
126
  end
@@ -9,14 +9,6 @@ module Faccts
9
9
  @fixed_code_template = RustCodeTemplate.new(fixed_template_fetcher_strategy)
10
10
  end
11
11
 
12
- def generate_from_test_suite!(test_specification_suite)
13
- @test_specification_suite = test_specification_suite
14
-
15
- return NO_CODE if test_specification_suite.empty?
16
-
17
- wrapped_in_fixed_code_template(code_from_test_specification_suite)
18
- end
19
-
20
12
  class RustCodeTemplate
21
13
  RUST_TEMPLATE_INSERT_SYMBOL = "/*{}*/"
22
14
 
@@ -43,46 +35,18 @@ module Faccts
43
35
  end
44
36
  end
45
37
 
46
- class BasicRustTestAssertionCallTemplateFetcher
47
- def code_template
48
- + " name = \"/*{}*/\";\n" \
49
- + " result = /*{}*/;\n" \
50
- + " result_output = if result == true { \"PASS\" } else { \"FAIL\" };\n" \
51
- + " test_result_output = format!(\"{},{}\", name, result_output);\n" \
52
- + " test_suite_result_output += &test_result_output;\n" \
53
- + " test_suite_result_output += \"\\n\";\n"
54
- end
55
- end
38
+ def generate_from_test_suite!(test_specification_suite)
39
+ @test_specification_suite = test_specification_suite
56
40
 
57
- class BasicRustMainProgramTemplateFetcher
58
- def code_template
59
- "use std::fs;\n" \
60
- + "mod fixture;\n" \
61
- + "\n" \
62
- + "use crate::fixture::*;\n" \
63
- + "\n" \
64
- + "fn main() {\n" \
65
- + " let mut test_suite_result_output = String::from(\"name,result\\n\");\n" \
66
- + " let mut name: &str;\n" \
67
- + " let mut result: bool;\n" \
68
- + " let mut result_output: &str;\n" \
69
- + " let mut test_result_output: String;\n" \
70
- + "\n" \
71
- + "/*{}*/" \
72
- + "\n" \
73
- + " let _ = fs::write(\"./results.faccts\", test_suite_result_output);\n" \
74
- + "}\n"
75
- end
41
+ return NO_CODE if test_specification_suite.empty?
42
+
43
+ wrapped_in_fixed_code_template(code_from_test_specification_suite)
76
44
  end
77
45
 
78
46
  private
79
47
 
80
48
  attr_reader :test_assertion_code_generator, :fixed_code_template, :test_specification_suite
81
49
 
82
- def wrapped_in_fixed_code_template(value)
83
- fixed_code_template.generate_with_values(value)
84
- end
85
-
86
50
  def code_from_test_specification_suite
87
51
  generated_test_assertion_list.join
88
52
  end
@@ -92,5 +56,9 @@ module Faccts
92
56
  test_assertion_code_generator.generate!(assert_specification)
93
57
  end
94
58
  end
59
+
60
+ def wrapped_in_fixed_code_template(value)
61
+ fixed_code_template.generate_with_values(value)
62
+ end
95
63
  end
96
64
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faccts
4
+ class RustCodeGenerator
5
+ class BasicRustMainProgramTemplateFetcher
6
+ def code_template
7
+ "use std::fs;\n" \
8
+ + "mod fixture;\n" \
9
+ + "\n" \
10
+ + "use crate::fixture::*;\n" \
11
+ + "\n" \
12
+ + "fn main() {\n" \
13
+ + " let mut test_suite_result_output = String::from(\"name,result\\n\");\n" \
14
+ + " let mut name: &str;\n" \
15
+ + " let mut result: bool;\n" \
16
+ + " let mut result_output: &str;\n" \
17
+ + " let mut test_result_output: String;\n" \
18
+ + "\n" \
19
+ + "/*{}*/" \
20
+ + "\n" \
21
+ + " let _ = fs::write(\"./results.faccts\", test_suite_result_output);\n" \
22
+ + "}\n"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faccts
4
+ class RustCodeGenerator
5
+ class BasicRustTestAssertionCallTemplateFetcher
6
+ def code_template
7
+ + " name = \"/*{}*/\";\n" \
8
+ + " result = /*{}*/;\n" \
9
+ + " result_output = if result == true { \"PASS\" } else { \"FAIL\" };\n" \
10
+ + " test_result_output = format!(\"{},{}\", name, result_output);\n" \
11
+ + " test_suite_result_output += &test_result_output;\n" \
12
+ + " test_suite_result_output += \"\\n\";\n"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Faccts
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/faccts.rb CHANGED
@@ -3,5 +3,26 @@
3
3
  require_relative "faccts/version"
4
4
  require "faccts"
5
5
 
6
+ require "faccts/entities/test_assertion"
7
+
8
+ require "faccts/01_loading_test_specification/yaml_file_reader"
9
+
10
+ require "faccts/02_parsing_test_specification/yaml_test_parser"
11
+ require "faccts/02_parsing_test_specification/yaml_test_assertion_parser"
12
+ require "faccts/02_parsing_test_specification/yaml_assertion_specification_parser"
13
+
14
+ require "faccts/03_generating_code/rust_code_generator"
15
+ require "faccts/03_generating_code/rust_name_to_function_call_converter"
16
+ require "faccts/03_generating_code/rust_test_assertion_code_generator"
17
+ require "faccts/03_generating_code/templates/basic_rust_main_program_template_fetcher"
18
+ require "faccts/03_generating_code/templates/basic_rust_test_assertion_call_template_fetcher"
19
+
20
+ require "faccts/04_exporting_results/rust_file_writer"
21
+
22
+ require "faccts/05_reporting_feedback/basic_console_output"
23
+
24
+ require "faccts/integration/acceptance_tester"
25
+ require "faccts/integration/basic_acceptance_tester"
26
+
6
27
  module Faccts
7
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faccts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - bull313
@@ -18,14 +18,16 @@ files:
18
18
  - Rakefile
19
19
  - exe/faccts
20
20
  - lib/faccts.rb
21
- - lib/faccts/01_loading_test_specification/file_reader.rb
21
+ - lib/faccts/01_loading_test_specification/yaml_file_reader.rb
22
22
  - lib/faccts/02_parsing_test_specification/yaml_assertion_specification_parser.rb
23
23
  - lib/faccts/02_parsing_test_specification/yaml_test_assertion_parser.rb
24
24
  - lib/faccts/02_parsing_test_specification/yaml_test_parser.rb
25
25
  - lib/faccts/03_generating_code/rust_code_generator.rb
26
26
  - lib/faccts/03_generating_code/rust_name_to_function_call_converter.rb
27
27
  - lib/faccts/03_generating_code/rust_test_assertion_code_generator.rb
28
- - lib/faccts/04_exporting_results/file_writer.rb
28
+ - lib/faccts/03_generating_code/templates/basic_rust_main_program_template_fetcher.rb
29
+ - lib/faccts/03_generating_code/templates/basic_rust_test_assertion_call_template_fetcher.rb
30
+ - lib/faccts/04_exporting_results/rust_file_writer.rb
29
31
  - lib/faccts/05_reporting_feedback/basic_console_output.rb
30
32
  - lib/faccts/entities/test_assertion.rb
31
33
  - lib/faccts/integration/acceptance_tester.rb