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

function calls can include integers and test script #2

Merged
merged 6 commits into from
Jul 25, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
4 changes: 2 additions & 2 deletions rockstarpy/rockstar.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def convert_code(rockstar_code, py_rockstar):
py_line = find_proper_variables(py_line)
py_line = find_common_variables(py_line)

py_line = re.sub(r'([A-Za-z]+(?: [A-Za-z]+)*) taking ([A-Za-z_]+(?:, [A-Za-z_]+)*)', r'\g<1>(\g<2>)', py_line)
py_line = re.sub(r'([A-Za-z]+(?: [A-Za-z]+)*) taking ([A-Za-z0-9_]+(?:, [A-Za-z_0-9]+)*)', r'\g<1>(\g<2>)', py_line)

line_named = find_named(py_line)
most_recently_named = line_named if line_named else most_recently_named
Expand All @@ -177,4 +177,4 @@ def convert_code(rockstar_code, py_rockstar):
py_rockstar.close()

else:
print('Usage: python rockstar.py input.{rock|rockstar|lyrics} output.py')
print('Usage: python rockstar.py input.{rock|rockstar|lyrics} output.py')
20 changes: 20 additions & 0 deletions tests/fizz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def Midnight(your_heart, your_soul):
while your_heart >= your_soul: #this is a comment
your_heart = your_heart - your_soul
return your_heart
Desire = 100
my_world = False
Fire = 3 #i love comments
Hate = 5
while not my_world == Desire:
my_world += 1
if Midnight(my_world, Fire) == False and Midnight(my_world, Hate) == False:
print("FizzBuzz!")
continue
if Midnight(my_world, Fire) == False:
print("Fizz!")
continue
if Midnight(my_world, Hate) == False:
print("Buzz!")
continue
print(my_world)
26 changes: 26 additions & 0 deletions tests/fizz.rock
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Midnight takes your heart and your soul
While your heart is as high as your soul (this is a comment)
Put your heart without your soul into your heart

Give back your heart


Desire is a lovestruck ladykiller
My world is nothing
Fire is ice (i love comments)
Hate is water
Until my world is Desire,
Build my world up
If Midnight taking my world, Fire is nothing and Midnight taking my world, Hate is nothing
Shout "FizzBuzz!"
Take it to the top

If Midnight taking my world, Fire is nothing
Shout "Fizz!"
Take it to the top

If Midnight taking my world, Hate is nothing
Say "Buzz!"
Take it to the top

Whisper my world
46 changes: 46 additions & 0 deletions tests/run_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
from io import StringIO
import difflib

from rockstarpy.rockstar import convert_code


def check_files_identical(expected, actual):
diff = difflib.unified_diff(
expected,
actual,
fromfile='expected',
tofile='actual',
)
diff = list(diff)
if len(diff):
for d in diff:
print(''.join(diff))
assert False, "There are differences"

def main():
files = os.listdir('.')
rock_files = filter(lambda f: f.split(".")[-1] in ['rock','rockstar','lyrics'] , files)
py_files = set(filter(lambda f: f.endswith('.py'), files))
for rock_file in rock_files:
print("testing", rock_file)
file_name = os.path.splitext(rock_file)[0] # take off extension
py_file = file_name + ".py"
assert py_file in py_files, "Did not create a corrosponding expected output for " + rock_file

converted_code = StringIO()
rockstar_code = ""
with open(rock_file, 'r') as rockstar_file:
rockstar_code = rockstar_file.readlines()

convert_code(rockstar_code, converted_code )
with open(file_name +".py", 'r') as expected:
expected_code = expected.read()
actual_code = converted_code.getvalue()
check_files_identical(expected_code, actual_code)
converted_code.close()

if __name__ == '__main__':
main()


3 changes: 3 additions & 0 deletions tests/testfunccall.numbers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def Multiply(Love, Life):
return Love * Life
Multiply(3, 444)
4 changes: 4 additions & 0 deletions tests/testfunccall.numbers.rock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Multiply takes Love and Life
Give back Love of Life

Multiply taking 3, 444
4 changes: 4 additions & 0 deletions tests/testfunccall.rock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Multiply takes Love and Life
Give back Love of Life

Multiply taking 3, 4
5 changes: 5 additions & 0 deletions tests/testfunccall.variables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def Multiply(Love, Life):
return Love * Life
my_heart = 1
the_devil = 666
Multiply(my_heart, the_devil)
6 changes: 6 additions & 0 deletions tests/testfunccall.variables.rock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Multiply takes Love and Life
Give back Love of Life

Put 1 into my heart
Put 666 into the devil
Multiply taking my heart, the devil