Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/main/java/com/example/LoxInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public String toString() {
}

Object get(Token name) {
if (fields.containsValue(name.lexeme)) {
if (fields.containsKey(name.lexeme)) {
return fields.get(name.lexeme);
}

Expand Down
24 changes: 24 additions & 0 deletions src/test/java/com/example/LoxInstanceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example;

import java.util.HashMap;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class LoxInstanceTest extends TestCase {
public LoxInstanceTest(String testName) {
super(testName);
}

public static Test suite() {
return new TestSuite(LoxInstanceTest.class);
}

public void testFieldAccess() {
LoxClass klass = new LoxClass("Foo", null, new HashMap<>());
LoxInstance instance = new LoxInstance(klass);
Token token = new Token(Token.TokenType.IDENTIFIER, "bar", null, 1);
instance.set(token, 42);
assertEquals(42, instance.get(token));
}
}