1 28 29 package org.jruby.ast.visitor.rewriter; 30 31 import junit.framework.TestCase; 32 33 public class SourceTestCase extends TestCase { 34 private String name; 35 private StringBuffer source = new StringBuffer (); 36 private StringBuffer expectedResult = new StringBuffer (); 37 private String generatedSource; 38 private boolean ignoreEmtpyLines; 39 40 public SourceTestCase(String name, boolean ignoreEmtpyLines) { 41 this.name = name; 42 this.ignoreEmtpyLines = ignoreEmtpyLines; 43 } 44 45 private void appendToBuffer(StringBuffer buffer, String line) { 46 if (line.matches("\\s*") && ignoreEmtpyLines) { 47 return; 48 } 49 if(!buffer.toString().equals("")) { 50 buffer.append("\n"); 51 } 52 buffer.append(line); 53 } 54 55 public void appendLineToSource(String line) { 56 appendToBuffer(source, line); 57 } 58 59 public void appendLineToExpectedResult(String line) { 60 appendToBuffer(expectedResult, line); 61 } 62 63 public String getSource() { 64 return source.toString(); 65 } 66 67 public String getName() { 68 return name; 69 } 70 71 private String getExpectedResult() { 72 return expectedResult.toString().equals("") ? source.toString() : expectedResult.toString(); 73 } 74 75 public void setGeneratedSource(String source) { 76 generatedSource = source; 77 } 78 79 public void runTest() { 80 if (!getExpectedResult().equals(generatedSource)) 81 System.out.println("G: " + generatedSource + ", E: " + getExpectedResult()); 82 assertEquals(getExpectedResult(), generatedSource); 83 } 84 } 85 | Popular Tags |