feat: restructured code
This commit is contained in:
19
pjvm/mockimpl/__init__.py
Normal file
19
pjvm/mockimpl/__init__.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from .system import JMockSystemIn, JMockSystemOut, mock_inputstream_read, mock_printstream_println
|
||||
|
||||
mock_static_objects = {
|
||||
'java/lang/System': {
|
||||
'out': JMockSystemOut(),
|
||||
'in': JMockSystemIn()
|
||||
}
|
||||
}
|
||||
|
||||
mock_instance_methods = {
|
||||
'java/io/PrintStream': {
|
||||
'println': mock_printstream_println
|
||||
},
|
||||
'java/io/InputStream': {
|
||||
'read': mock_inputstream_read
|
||||
}
|
||||
}
|
||||
|
||||
__all__ = ['mock_instance_methods', 'mock_static_objects']
|
||||
31
pjvm/mockimpl/system.py
Normal file
31
pjvm/mockimpl/system.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""
|
||||
In here the System module is partially implemented
|
||||
"""
|
||||
import sys
|
||||
from typing import List
|
||||
|
||||
from ..old_jtypes import JObj, JInteger
|
||||
|
||||
|
||||
class JMockSystemOut(JObj):
|
||||
type = "Ljava/io/PrintStream;"
|
||||
value = None
|
||||
|
||||
|
||||
class JMockSystemIn(JObj):
|
||||
type = "Ljava/io/InputStream;"
|
||||
value = None
|
||||
|
||||
|
||||
def mock_printstream_println(self: JObj, args: List[JObj]):
|
||||
if len(args) != 1:
|
||||
raise ValueError("Argument length mismatch")
|
||||
if args[0].type != 'java/lang/String':
|
||||
raise ValueError("Argument type mismatch")
|
||||
|
||||
print(args[0].value)
|
||||
|
||||
|
||||
def mock_inputstream_read(self: JObj, args: List[JObj]):
|
||||
character = sys.stdin.read(1).strip()
|
||||
return JInteger(ord(character))
|
||||
Reference in New Issue
Block a user