-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83e3bfc
commit 015d2bd
Showing
50 changed files
with
3,786 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[tool.poetry] | ||
name = "rewrite-test" | ||
version = "0.0.0" # This will be replaced by the GitHub Actions workflow | ||
description = "Test functionality for the OpenRewrite library" | ||
authors = ["Moderne Inc. <support@moderne.io>"] | ||
license = "Apache-2.0" | ||
packages = [ | ||
{ include = "rewrite/test", from = "src" } | ||
] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.8" | ||
rewrite-core = { path = "../rewrite-core", develop = true } | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
pytest = "^8.3.2" | ||
|
||
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
build-backend = "poetry.core.masonry.api" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from dataclasses import dataclass | ||
from uuid import UUID | ||
|
||
@dataclass(frozen=True, eq=False) | ||
class SourceSpec: | ||
_id: UUID | ||
|
||
@property | ||
def id(self) -> UUID: | ||
return self._id | ||
|
||
_parser: ParserBuilder | ||
|
||
@property | ||
def parser(self) -> ParserBuilder: | ||
return self._parser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from abc import ABC | ||
|
||
class RewriteTest(ABC): | ||
def rewrite_run(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
root = true | ||
|
||
[*.java] | ||
indent_size = 4 | ||
ij_continuation_indent_size = 2 |
51 changes: 51 additions & 0 deletions
51
rewrite/rewrite-test/tests/java/org/openrewrite/python/ChangeMethodNameTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2023 the original author or authors. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.openrewrite.python; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.openrewrite.DocumentExample; | ||
import org.openrewrite.test.RecipeSpec; | ||
import org.openrewrite.test.RewriteTest; | ||
|
||
import static org.openrewrite.python.Assertions.python; | ||
|
||
class ChangeMethodNameTest implements RewriteTest { | ||
|
||
@Override | ||
public void defaults(RecipeSpec spec) { | ||
spec.recipe(new ChangeMethodName("print", "println", true)); | ||
} | ||
|
||
@DocumentExample | ||
@Test | ||
void renameMethod() { | ||
rewriteRun( | ||
python( | ||
""" | ||
class Foo: | ||
def foo() : | ||
print("hello") | ||
""", | ||
""" | ||
class Foo: | ||
def foo() : | ||
println("hello") | ||
""" | ||
) | ||
); | ||
} | ||
|
||
} |
105 changes: 105 additions & 0 deletions
105
rewrite/rewrite-test/tests/java/org/openrewrite/python/cleanup/StartsWithEndsWithTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.openrewrite.python.cleanup; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.openrewrite.DocumentExample; | ||
import org.openrewrite.test.RecipeSpec; | ||
import org.openrewrite.test.RewriteTest; | ||
|
||
import static org.openrewrite.python.Assertions.python; | ||
|
||
@SuppressWarnings({"PyInterpreter", "PyUnresolvedReferences"}) | ||
class StartsWithEndsWithTest implements RewriteTest { | ||
@Override | ||
public void defaults(RecipeSpec spec) { | ||
spec.recipe(new StartsWithEndsWith()); | ||
} | ||
|
||
@Test | ||
@DocumentExample | ||
void startswithAndEndswith() { | ||
rewriteRun( | ||
python( | ||
""" | ||
a_string = "ababab" | ||
if a_string.startswith("ab") or a_string.startswith("aba"): | ||
print("Starts with ab") | ||
if a_string.startswith("ab") or a_string.startswith("aba") or a_string.startswith("abab"): | ||
print("Starts with ab") | ||
if a_string.endswith("ab") or a_string.endswith("bab"): | ||
print("Ends with ab") | ||
""", | ||
""" | ||
a_string = "ababab" | ||
if a_string.startswith(("ab", "aba")): | ||
print("Starts with ab") | ||
if a_string.startswith(("ab", "aba", "abab")): | ||
print("Starts with ab") | ||
if a_string.endswith(("ab", "bab")): | ||
print("Ends with ab") | ||
""" | ||
) | ||
); | ||
} | ||
|
||
@Test | ||
void morePositiveCases() { | ||
rewriteRun( | ||
python( | ||
""" | ||
a_string = "ababab" | ||
a_string.startswith("ab") or a_string.startswith("aba") or a_string.startswith("abab") or a_string.startswith("ababa") | ||
a_string.startswith("ab") or a_string.startswith(("aba", "abab")) | ||
a_string.startswith(("ab", "aba")) or a_string.startswith(("abab", "ababa")) | ||
""", | ||
""" | ||
a_string = "ababab" | ||
a_string.startswith(("ab", "aba", "abab", "ababa")) | ||
a_string.startswith(("ab", "aba", "abab")) | ||
a_string.startswith(("ab", "aba", "abab", "ababa")) | ||
""" | ||
) | ||
); | ||
} | ||
|
||
@Test | ||
void negativeCases() { | ||
rewriteRun( | ||
python( | ||
""" | ||
a_string = "ababab" | ||
b_string = "babab" | ||
a_string.startswith("ab") | ||
a_string.startswith(("ab", "aba")) | ||
a_string.startswith("aba") and a_string.startswith("ab") | ||
a_string.startswith("aba") and a_string.startswith("ab") or True | ||
a_string.startswith("aba") or b_string.startswith("ba") | ||
a_string.startswith("aba") or a_string.endswith("bab") | ||
""" | ||
) | ||
); | ||
} | ||
} |
Oops, something went wrong.