Skip to content

react: Move inputs (cells, operations) to input object#1130

Merged
petertseng merged 2 commits intoexercism:masterfrom
petertseng:react
Jan 16, 2018
Merged

react: Move inputs (cells, operations) to input object#1130
petertseng merged 2 commits intoexercism:masterfrom
petertseng:react

Conversation

@petertseng
Copy link
Copy Markdown
Member

react 1.1.0

As proposed and accepted in #996

indent = false
operations = false

ARGF.each_line { |l|
  if l.include?('version')
    ver = l.split(?")[3]
    ver_components = ver.split(?.).map(&:to_i)
    ver_components[1] += 1
    ver_components[2] = 0
    l[ver] = ver_components.join(?.)
  end

  first_non_space = l.index(/\S/)
  if l.include?('"cells"')
    puts ' ' * first_non_space + '"input": {'
    indent = true
  end
  operations ||= l.include?('"operations"')
  l.delete!(?,) if operations && l.strip == '],'
  puts "#{'  ' if indent}#{l}"
  if operations && l.strip == ?]
    puts ' ' * first_non_space + '},'
    operations = false
    indent = false
  end
}

also note the additional commit that adds "expected": {}, since it's required but we expect nothing other than what was already expected in operations.

In the new schema in #1074, expected is REQUIRED. Since all expectations
are encoded in the `operations` array, we just expect nothing.

```ruby
operations = false

ARGF.each_line { |l|
  operations ||= l.include?('"operations"')
  first_non_space = l.index(/\S/)
  if operations && l.strip == ?]
    l["\n"] = ",\n"
    puts l
    puts ' ' * first_non_space + '"expected": {}'
    operations = false
  else
    puts l
  end
}
```
react 1.1.0

As proposed and accepted in #996

```ruby
indent = false
operations = false

ARGF.each_line { |l|
  if l.include?('version')
    ver = l.split(?")[3]
    ver_components = ver.split(?.).map(&:to_i)
    ver_components[1] += 1
    ver_components[2] = 0
    l[ver] = ver_components.join(?.)
  end

  first_non_space = l.index(/\S/)
  if l.include?('"cells"')
    puts ' ' * first_non_space + '"input": {'
    indent = true
  end
  operations ||= l.include?('"operations"')
  l.delete!(?,) if operations && l.strip == '],'
  puts "#{'  ' if indent}#{l}"
  if operations && l.strip == ?]
    puts ' ' * first_non_space + '},'
    operations = false
    indent = false
  end
}
```
],
"operations": [
{
"type": "expect_cell_value",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In its current state, it is not possible to consistently place expect_cell_value in expected, so I do not.

],
"operations": [
{
"type": "expect_cell_value",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this expect_cell_value comes before a set_value, therefore it is not possible to consistently place expect_cell_value in expected. Ordering is important. To place expect_cell_value in expected, we would need to redefine how expect_cell_value works so that it may refer to a point in time before/after certain other operations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants