Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trailing string #21

Closed
schneems opened this issue Dec 3, 2020 · 5 comments
Closed

Trailing string #21

schneems opened this issue Dec 3, 2020 · 5 comments

Comments

@schneems
Copy link
Collaborator

schneems commented Dec 3, 2020

require "rails_helper"
RSpec.describe TelehealthAppointment, type: :model do
  describe "#participants_state" do
    context "timezones workaround" do
      it "should receive a time in UTC format and return the time with the"\
        "office's UTC offset substracted from it" do
        travel_to DateTime.new(2020, 10, 1, 10, 0, 0) do
          office = build(:office)
        end
      end
    end
  end
  describe "#past?" do
    context "more than 15 min have passed since appointment start time" do
      it "returns true" do # <== HERE
    end
  end
end

The it "returns true" do is the problem but due to the indentation it says:

   1  require "rails_helper"
   2  RSpec.describe TelehealthAppointment, type: :model do
   3    describe "#participants_state" do
   4      context "timezones workaround" do
   5        it "should receive a time in UTC format and return the time with the"\
❯  6          "office's UTC offset substracted from it" do
❯  7          travel_to DateTime.new(2020, 10, 1, 10, 0, 0) do
❯  9          end
  10        end
  11      end
  12    end
  13    describe "#past?" do
  14      context "more than 15 min have passed since appointment start time" do
  15        it "returns true" do # <== HERE
  16      end
  17    end
  18  end

Which is incorrect

@schneems schneems changed the title Trailing string: Trailing string Dec 3, 2020
@schneems
Copy link
Collaborator Author

schneems commented Dec 4, 2020

@schneems
Copy link
Collaborator Author

schneems commented Dec 4, 2020

I'm thinking that when i'm creating code_lines, I could check to see if a line ends in a slash \ and if it does, group it with the next line so this:

5        it "should receive a time in UTC format and return the time with the"\
6          "office's UTC offset substracted from it" do

Would become

5        it "should receive a time in UTC format and return the time with the" "office's UTC offset substracted from it" do
6        # Make invisible

It's a bit of a special case, but re-formatting the document in this way would allow us to handle this case without any changes to the search logic.

Consequences: It would be confusing if this line ends up being in the error output for the end user. So it's not ideal. I could maybe record the modification, and then un-do it later if it's seen that this line is part of the output. That might not be too difficult

Alternatively I could try to add logic that says every "do" must be paired with a method i.e. do; end is not valid syntax you need thing do; end, this is tricky because right now code lines only know about themselves while trailing do can be on a newline

Dir.chdir("/tmp") \
do
end

Handling these cases with the current implementation would be more difficult. It would be easier to handle this special case as a pre/post processing step.

@schneems
Copy link
Collaborator Author

schneems commented Dec 9, 2020

It now returns:

   2  RSpec.describe TelehealthAppointment, type: :model do
   3    describe "#participants_state" do
   4      context "timezones workaround" do
   5        it "should receive a time in UTC format and return the time with the"\
❯  6          "office's UTC offset substracted from it" do
  10        end
  11      end
  12    end
  18  end

Which is still wrong, but it's a different wrong

@schneems
Copy link
Collaborator Author

schneems commented Dec 9, 2020

Update, this is not an issue because Foo.call "a", \"b", is not syntatical valid due to the trailing comma

You can have a trailing do without a \

Foo.call "a",
  "b",
  "c" do
end
Syntax OK

@schneems
Copy link
Collaborator Author

schneems commented Dec 9, 2020

Possibility to detect trailing do: appending an end and seeing if it becomes valid.

  • Yes: Not a trailing do
  • No: Needs more than an end, might be missing the initial on_ident
  "c" do ;  end # Still invalid even with an end

schneems added a commit that referenced this issue Dec 10, 2020
Ruby lines that end with a slash `\` indicate that the next line should be concatenated with the current line so:

```ruby
  if "trailing" \
     "line" do
  end
```

Is functionally equivalent to:

```ruby
  if "trailing" "line" do
  endf
```

We can replicate this logic by taking note when a line ends with a trailing slash and then concatenating it with the next line.

Functionally the TrailingSlashJoin class does this by concatenating the lines, and then hiding the original line.

To allow for output, the DisplayCodeWithLineNumbers is now aware that a code line may contain multiple code lines, and it will split and render each.
schneems added a commit that referenced this issue Dec 10, 2020
[Close #21] Concat lines with trailing slash
schneems added a commit that referenced this issue Dec 16, 2020
Ruby lines that end with a slash `\` indicate that the next line should be concatenated with the current line so:

```ruby
  if "trailing" \
     "line" do
  end
```

Is functionally equivalent to:

```ruby
  if "trailing" "line" do
  endf
```

We can replicate this logic by taking note when a line ends with a trailing slash and then concatenating it with the next line.

Functionally the TrailingSlashJoin class does this by concatenating the lines, and then hiding the original line.

To allow for output, the DisplayCodeWithLineNumbers is now aware that a code line may contain multiple code lines, and it will split and render each.
schneems added a commit that referenced this issue Jan 15, 2022
# This is the 1st commit message:

Move queue logic and engulf logic to a class

The queuing and engulfing logic are tied together. We can bundle the two of them into a single class with a specific interface.
# This is the commit message #2:

WIP A*ish

# This is the commit message #3:

WIP with lex_diff OMG

# This is the commit message #4:

WIP Pull out "grab equal" logic of UpDownExpand

# This is the commit message #5:

WIP move class to proper file location

# This is the commit message #6:

WIP Fix spelling of method

# This is the commit message #7:

WIP LOL search

# This is the commit message #8:

Runs, finds the large code blocks, but is too greedy

# This is the commit message #9:

Move LexDiff to own class, refactor to an array

We're never using the hash keys so we don't need them. We can save memory and time by storing the values as an array.

# This is the commit message #10:

WIP LOL spec

# This is the commit message #11:

Micro optimize lex diff

# This is the commit message #12:

UpDownExpand fix major bug with internal mutability

When calling `line.lex_detect.dup` it was duplicating the outer memory, but not the inner memory. Internally we're using an array and the old array was still being referenced and mutated.

# This is the commit message #13:

LexDiff Huge perf upgrade

Store values in the object instead of an array.

# This is the commit message #14:

WIP playing with fuzzing this into the old algorithm

# This is the commit message #15:

WORKS and is hella fast

# This is the commit message #16:

WIP docs

# This is the commit message #17:

Put a max band on number of iterations

Unbounded while loops scare me, in theory this class should never iterate more than line times, but mistakes happen. When they do I want feedback for the user without disrupting the rest of their program.

# This is the commit message #18:

WIP Cleanup and docs

# This is the commit message #19:

WIP Cleanup and docs

# This is the commit message #20:

Standardrb

# This is the commit message #21:

Standardrb

# This is the commit message #22:

Refactor LexDiff, remove unused methods, add docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant