Fix core tests
This commit is contained in:
parent
2488c1047b
commit
0fabf7daff
@ -49,6 +49,7 @@ public class MarkwonImplTest {
|
|||||||
null,
|
null,
|
||||||
mock(Parser.class),
|
mock(Parser.class),
|
||||||
mock(MarkwonVisitorFactory.class),
|
mock(MarkwonVisitorFactory.class),
|
||||||
|
mock(MarkwonConfiguration.class),
|
||||||
Collections.singletonList(plugin));
|
Collections.singletonList(plugin));
|
||||||
|
|
||||||
impl.parse("whatever");
|
impl.parse("whatever");
|
||||||
@ -72,6 +73,7 @@ public class MarkwonImplTest {
|
|||||||
null,
|
null,
|
||||||
parser,
|
parser,
|
||||||
mock(MarkwonVisitorFactory.class),
|
mock(MarkwonVisitorFactory.class),
|
||||||
|
mock(MarkwonConfiguration.class),
|
||||||
Arrays.asList(first, second));
|
Arrays.asList(first, second));
|
||||||
|
|
||||||
impl.parse("zero");
|
impl.parse("zero");
|
||||||
@ -99,6 +101,7 @@ public class MarkwonImplTest {
|
|||||||
null,
|
null,
|
||||||
mock(Parser.class),
|
mock(Parser.class),
|
||||||
visitorFactory,
|
visitorFactory,
|
||||||
|
mock(MarkwonConfiguration.class),
|
||||||
Collections.singletonList(plugin));
|
Collections.singletonList(plugin));
|
||||||
|
|
||||||
when(visitorFactory.create()).thenReturn(visitor);
|
when(visitorFactory.create()).thenReturn(visitor);
|
||||||
@ -145,6 +148,7 @@ public class MarkwonImplTest {
|
|||||||
null,
|
null,
|
||||||
mock(Parser.class),
|
mock(Parser.class),
|
||||||
visitorFactory,
|
visitorFactory,
|
||||||
|
mock(MarkwonConfiguration.class),
|
||||||
Collections.<MarkwonPlugin>emptyList());
|
Collections.<MarkwonPlugin>emptyList());
|
||||||
|
|
||||||
impl.render(mock(Node.class));
|
impl.render(mock(Node.class));
|
||||||
@ -180,6 +184,7 @@ public class MarkwonImplTest {
|
|||||||
null,
|
null,
|
||||||
mock(Parser.class),
|
mock(Parser.class),
|
||||||
visitorFactory,
|
visitorFactory,
|
||||||
|
mock(MarkwonConfiguration.class),
|
||||||
Collections.singletonList(plugin));
|
Collections.singletonList(plugin));
|
||||||
|
|
||||||
final AtomicBoolean flag = new AtomicBoolean(false);
|
final AtomicBoolean flag = new AtomicBoolean(false);
|
||||||
@ -218,6 +223,7 @@ public class MarkwonImplTest {
|
|||||||
null,
|
null,
|
||||||
mock(Parser.class),
|
mock(Parser.class),
|
||||||
mock(MarkwonVisitorFactory.class, RETURNS_MOCKS),
|
mock(MarkwonVisitorFactory.class, RETURNS_MOCKS),
|
||||||
|
mock(MarkwonConfiguration.class),
|
||||||
Collections.singletonList(plugin));
|
Collections.singletonList(plugin));
|
||||||
|
|
||||||
final TextView textView = mock(TextView.class);
|
final TextView textView = mock(TextView.class);
|
||||||
@ -265,6 +271,7 @@ public class MarkwonImplTest {
|
|||||||
null,
|
null,
|
||||||
mock(Parser.class),
|
mock(Parser.class),
|
||||||
mock(MarkwonVisitorFactory.class),
|
mock(MarkwonVisitorFactory.class),
|
||||||
|
mock(MarkwonConfiguration.class),
|
||||||
plugins);
|
plugins);
|
||||||
|
|
||||||
assertTrue("First", impl.hasPlugin(First.class));
|
assertTrue("First", impl.hasPlugin(First.class));
|
||||||
@ -287,6 +294,7 @@ public class MarkwonImplTest {
|
|||||||
textSetter,
|
textSetter,
|
||||||
mock(Parser.class),
|
mock(Parser.class),
|
||||||
mock(MarkwonVisitorFactory.class),
|
mock(MarkwonVisitorFactory.class),
|
||||||
|
mock(MarkwonConfiguration.class),
|
||||||
Collections.singletonList(plugin));
|
Collections.singletonList(plugin));
|
||||||
|
|
||||||
final TextView textView = mock(TextView.class);
|
final TextView textView = mock(TextView.class);
|
||||||
@ -330,6 +338,7 @@ public class MarkwonImplTest {
|
|||||||
null,
|
null,
|
||||||
mock(Parser.class),
|
mock(Parser.class),
|
||||||
mock(MarkwonVisitorFactory.class),
|
mock(MarkwonVisitorFactory.class),
|
||||||
|
mock(MarkwonConfiguration.class),
|
||||||
plugins);
|
plugins);
|
||||||
|
|
||||||
// should be returned
|
// should be returned
|
||||||
@ -360,6 +369,7 @@ public class MarkwonImplTest {
|
|||||||
null,
|
null,
|
||||||
mock(Parser.class),
|
mock(Parser.class),
|
||||||
mock(MarkwonVisitorFactory.class),
|
mock(MarkwonVisitorFactory.class),
|
||||||
|
mock(MarkwonConfiguration.class),
|
||||||
plugins);
|
plugins);
|
||||||
|
|
||||||
final List<? extends MarkwonPlugin> list = impl.getPlugins();
|
final List<? extends MarkwonPlugin> list = impl.getPlugins();
|
||||||
|
@ -64,13 +64,13 @@ public class EditorActivity extends Activity {
|
|||||||
private void simple_process() {
|
private void simple_process() {
|
||||||
// Process highlight in-place (right after text has changed)
|
// Process highlight in-place (right after text has changed)
|
||||||
|
|
||||||
// obtain Markwon instance
|
// obtain Markwon instance
|
||||||
final Markwon markwon = Markwon.create(this);
|
final Markwon markwon = Markwon.create(this);
|
||||||
|
|
||||||
// create editor
|
// create editor
|
||||||
final MarkwonEditor editor = MarkwonEditor.create(markwon);
|
final MarkwonEditor editor = MarkwonEditor.create(markwon);
|
||||||
|
|
||||||
// set edit listener
|
// set edit listener
|
||||||
editText.addTextChangedListener(MarkwonEditorTextWatcher.withProcess(editor));
|
editText.addTextChangedListener(MarkwonEditorTextWatcher.withProcess(editor));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,25 +80,6 @@ public class EditorActivity extends Activity {
|
|||||||
final Markwon markwon = Markwon.create(this);
|
final Markwon markwon = Markwon.create(this);
|
||||||
final MarkwonEditor editor = MarkwonEditor.create(markwon);
|
final MarkwonEditor editor = MarkwonEditor.create(markwon);
|
||||||
|
|
||||||
editor.process(editText.getText());
|
|
||||||
|
|
||||||
// please note that MarkwonEditor operates on caller thread,
|
|
||||||
// fi you wish to execute this operation in background - this method
|
|
||||||
// must be called from background thread
|
|
||||||
editor.preRender(editText.getText(), new MarkwonEditor.PreRenderResultListener() {
|
|
||||||
@Override
|
|
||||||
public void onPreRenderResult(@NonNull MarkwonEditor.PreRenderResult result) {
|
|
||||||
// it's wise to check if rendered result is for the same input,
|
|
||||||
// for example by matching raw input
|
|
||||||
if (editText.getText().toString().equals(result.resultEditable().toString())) {
|
|
||||||
|
|
||||||
// if you are in background thread do not forget
|
|
||||||
// to execute dispatch in main thread
|
|
||||||
result.dispatchTo(editText.getText());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
editText.addTextChangedListener(MarkwonEditorTextWatcher.withPreRender(
|
editText.addTextChangedListener(MarkwonEditorTextWatcher.withPreRender(
|
||||||
editor,
|
editor,
|
||||||
Executors.newCachedThreadPool(),
|
Executors.newCachedThreadPool(),
|
||||||
@ -108,7 +89,7 @@ editor.preRender(editText.getText(), new MarkwonEditor.PreRenderResultListener()
|
|||||||
private void custom_punctuation_span() {
|
private void custom_punctuation_span() {
|
||||||
// Use own punctuation span
|
// Use own punctuation span
|
||||||
|
|
||||||
final MarkwonEditor editor = MarkwonEditor.builder(Markwon.create(this))
|
final MarkwonEditor editor = MarkwonEditor.builder(Markwon.create(this))
|
||||||
.withPunctuationSpan(CustomPunctuationSpan.class, CustomPunctuationSpan::new)
|
.withPunctuationSpan(CustomPunctuationSpan.class, CustomPunctuationSpan::new)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@ -118,7 +99,7 @@ final MarkwonEditor editor = MarkwonEditor.builder(Markwon.create(this))
|
|||||||
private void additional_edit_span() {
|
private void additional_edit_span() {
|
||||||
// An additional span is used to highlight strong-emphasis
|
// An additional span is used to highlight strong-emphasis
|
||||||
|
|
||||||
final MarkwonEditor editor = MarkwonEditor.builder(Markwon.create(this))
|
final MarkwonEditor editor = MarkwonEditor.builder(Markwon.create(this))
|
||||||
// This is required for edit-span cache
|
// This is required for edit-span cache
|
||||||
// We could use Markwon `StrongEmphasisSpan` here, but I use a different
|
// We could use Markwon `StrongEmphasisSpan` here, but I use a different
|
||||||
// one to indicate that those are completely unrelated spans and must be
|
// one to indicate that those are completely unrelated spans and must be
|
||||||
@ -335,11 +316,11 @@ final MarkwonEditor editor = MarkwonEditor.builder(Markwon.create(this))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class CustomPunctuationSpan extends ForegroundColorSpan {
|
private static class CustomPunctuationSpan extends ForegroundColorSpan {
|
||||||
CustomPunctuationSpan() {
|
CustomPunctuationSpan() {
|
||||||
super(0xFFFF0000); // RED
|
super(0xFFFF0000); // RED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Bold extends MetricAffectingSpan {
|
private static class Bold extends MetricAffectingSpan {
|
||||||
public Bold() {
|
public Bold() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user