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

Fix off-by-one issue in isOverlapping #2066

Merged
merged 6 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/org/rascalmpl/library/Prelude.java
Original file line number Diff line number Diff line change
Expand Up @@ -4110,9 +4110,9 @@ public IBool isOverlapping(ISourceLocation first, ISourceLocation second) {
if (first.hasOffsetLength()) {
if (second.hasOffsetLength()) {
int firstStart = first.getOffset();
int firstEnd = firstStart + first.getLength();
int firstEnd = firstStart + first.getLength() - 1; // Inclusive
int secondStart = second.getOffset();
int secondEnd = secondStart + second.getLength();
int secondEnd = secondStart + second.getLength() - 1; // Inclusive

return values.bool(
(firstStart <= secondStart && secondStart <= firstEnd)
Expand Down
20 changes: 20 additions & 0 deletions src/org/rascalmpl/library/lang/rascal/tests/library/Location.rsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@license{
Copyright (c) 2013-2024 CWI
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
}
module lang::rascal::tests::library::Location

import Location;

test bool isOverlapping1() = isOverlapping(|unknown:///|(0, 2), |unknown:///|(0, 2));
Copy link
Member

Choose a reason for hiding this comment

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

how about moving this to this already existing file with location tests?

// isOverlapping
test bool isOverlapping1(int _){
<l1, l2> = makeLocsWithGap(-1);
return report(l1, l2, isOverlapping(l1, l2));
}
test bool isOverlapping2(int _){
<l1, l2> = makeLocsWithGap(10);
return !isOverlapping(l1, l2);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, sure, I'll do.

For future reference, though, which tests go in lang::rascal::tests::basic::* and which tests go in lang::rascal::tests::library::*? I was assuming that tests related to language primitives would go in basic::* and tests for library functions in library::*, but I now also notice for instance:

test bool tstArbBool() { b = arbBool() ; return b == true || b == false; }

And:

test bool arb2(){
bool B = arbBool();
return (B == true) || (B == false);
}

Copy link
Member

Choose a reason for hiding this comment

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

I have no good answer for this. Maybe @jurgenvinju or @PaulKlint remembers the reason for the split?

In general, I just look at where other functions from the same module are tested.

Copy link
Member

Choose a reason for hiding this comment

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

I am the first to admit that this organization can (and should) be improved, but the ratio is this:

  • tests for languages features go to basic, functionality or one of the other more specialized directories
  • tests for the standard libraries go to library

As a consequence, tests for, say, locations can be found in two places. Not very good. The problem is that there are several dimensions that can be used to organize the tests:

  • syntactic category (e.g., expression, function, pattern, extend, import)
  • syntactic alternative (e.g., call, addition, is-defined)
  • language feature (e.g., dynamic dispatch, overloading, memoization, parsing)
  • data types (e.g., bool, int, map).
  • library modules (e.g., Location)

In many cases there is overlap between the categories. Come up with a better organization and I will be happy to implement it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, thanks for clarifying!

test bool isOverlapping2() = isOverlapping(|unknown:///|(0, 2), |unknown:///|(1, 2));
test bool isOverlapping3() = !isOverlapping(|unknown:///|(0, 2), |unknown:///|(2, 2));
test bool isOverlapping4() = isOverlapping(|unknown:///|(1, 2), |unknown:///|(0, 2));
test bool isOverlapping5() = isOverlapping(|unknown:///|(1, 2), |unknown:///|(1, 2));
test bool isOverlapping6() = isOverlapping(|unknown:///|(1, 2), |unknown:///|(2, 2));
test bool isOverlapping7() = !isOverlapping(|unknown:///|(2, 2), |unknown:///|(0, 2));
test bool isOverlapping8() = isOverlapping(|unknown:///|(2, 2), |unknown:///|(1, 2));
test bool isOverlapping9() = isOverlapping(|unknown:///|(2, 2), |unknown:///|(2, 2));
Loading