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

API to disable span support #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

dnkoutso
Copy link

This mode unlocks the ability for consumers to disable span support. This enables writing pure unit tests that do not depend on SpannableStringBuilder which otherwise would require Robolectric to run and make the tests much much slower.

Fixed all warnings too.

@loganj @ChrisRenke @rjrjr

@@ -67,6 +68,12 @@
private char curChar;
private int curCharIndex;

/**
* When enabled, span support is disabled. This can be useful for unit tests that don't want
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might need a bit help to word this better.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first sentence is redundant with field name. Just keep the second sentence ("This can be useful...").

@@ -214,6 +234,12 @@ public CharSequence format() {
return formatted;
}

/** Set whether span support is enabled or not. */
@SuppressWarnings("UnusedDeclaration") // Public API.
public void setDisableSpanSupport(boolean disableSpanSupport) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invert: setSpanSupportEnabled. default to true.

javadoc should indicate default. move javadoc from field to this method.

import static java.util.regex.Matcher.quoteReplacement;
import static java.util.regex.Pattern.quote;

public class SimpleEditable implements Editable {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final. definitely not public. needs javadoc.

* Default is <code>true</code>.
*/
@SuppressWarnings("UnusedDeclaration") // Public API.
public void setSpanSupportEnabled(boolean spanSupportedEnabled) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered just making this variable final, and having new factory methods for it? There'd be a lot of method proliferation I guess.

I was thinking of something like Phrase.stubSpan().from(...) or Phrase.stubSpanFrom(...) or something. That way you just have a small amount of code to add across a lot of tests.

I'd just like someone to avoid running into this method in their normal Phrase usage.

@pforhan
Copy link
Contributor

pforhan commented Mar 14, 2016

LGTM

/**
* This can be useful for unit tests that don't want to use {@link SpannableStringBuilder}
* which can cause a stub exception or be no-op.
* Default is <code>true</code>.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should change that since I switched it, it should say <code>false</code>

@dnkoutso dnkoutso force-pushed the dimitris/android-dep branch 2 times, most recently from bdc9261 to d57d3d8 Compare March 16, 2016 19:00
@pforhan
Copy link
Contributor

pforhan commented Oct 29, 2019

We should merge this, just noticed we've been using it for a looong time right off this commit.

We may want to pursue some sort of "default" span enabled setting that would enable even easier test writing

@dnkoutso dnkoutso force-pushed the dimitris/android-dep branch 2 times, most recently from a876d9b to 663ca14 Compare October 30, 2019 20:01
@pforhan pforhan mentioned this pull request May 28, 2020
@pforhan
Copy link
Contributor

pforhan commented Apr 6, 2022

@edenman we should get this in for a release

@pforhan
Copy link
Contributor

pforhan commented Apr 6, 2022

@dnkoutso want to rebase?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants