Merge "aconfig: change java flag method name to camelCase" am: 59d662524c
am: bec4ce710f
Original change: https://android-review.googlesource.com/c/platform/build/+/2626776 Change-Id: I371b95a00f483f2a30ccc6e67cb3ffb7c332dccd Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
9c7c5dabaa
2 changed files with 51 additions and 27 deletions
|
@ -86,10 +86,26 @@ fn create_class_element(package: &str, item: &Item) -> ClassElement {
|
|||
device_config_flag,
|
||||
flag_name_constant_suffix: item.name.to_ascii_uppercase(),
|
||||
is_read_write: item.permission == Permission::ReadWrite,
|
||||
method_name: item.name.clone(),
|
||||
method_name: format_java_method_name(&item.name),
|
||||
}
|
||||
}
|
||||
|
||||
fn format_java_method_name(flag_name: &str) -> String {
|
||||
flag_name
|
||||
.split('_')
|
||||
.filter(|&word| !word.is_empty())
|
||||
.enumerate()
|
||||
.map(|(index, word)| {
|
||||
if index == 0 {
|
||||
word.to_ascii_lowercase()
|
||||
} else {
|
||||
word[0..1].to_ascii_uppercase() + &word[1..].to_ascii_lowercase()
|
||||
}
|
||||
})
|
||||
.collect::<Vec<String>>()
|
||||
.join("")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
@ -102,17 +118,17 @@ mod tests {
|
|||
let expect_flags_content = r#"
|
||||
package com.android.aconfig.test;
|
||||
public final class Flags {
|
||||
public static boolean disabled_ro() {
|
||||
return FEATURE_FLAGS.disabled_ro();
|
||||
public static boolean disabledRo() {
|
||||
return FEATURE_FLAGS.disabledRo();
|
||||
}
|
||||
public static boolean disabled_rw() {
|
||||
return FEATURE_FLAGS.disabled_rw();
|
||||
public static boolean disabledRw() {
|
||||
return FEATURE_FLAGS.disabledRw();
|
||||
}
|
||||
public static boolean enabled_ro() {
|
||||
return FEATURE_FLAGS.enabled_ro();
|
||||
public static boolean enabledRo() {
|
||||
return FEATURE_FLAGS.enabledRo();
|
||||
}
|
||||
public static boolean enabled_rw() {
|
||||
return FEATURE_FLAGS.enabled_rw();
|
||||
public static boolean enabledRw() {
|
||||
return FEATURE_FLAGS.enabledRw();
|
||||
}
|
||||
private static FeatureFlags FEATURE_FLAGS = new FeatureFlagsImpl();
|
||||
|
||||
|
@ -123,11 +139,11 @@ mod tests {
|
|||
import android.provider.DeviceConfig;
|
||||
public final class FeatureFlagsImpl implements FeatureFlags {
|
||||
@Override
|
||||
public boolean disabled_ro() {
|
||||
public boolean disabledRo() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean disabled_rw() {
|
||||
public boolean disabledRw() {
|
||||
return DeviceConfig.getBoolean(
|
||||
"aconfig_test",
|
||||
"com.android.aconfig.test.disabled_rw",
|
||||
|
@ -135,11 +151,11 @@ mod tests {
|
|||
);
|
||||
}
|
||||
@Override
|
||||
public boolean enabled_ro() {
|
||||
public boolean enabledRo() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean enabled_rw() {
|
||||
public boolean enabledRw() {
|
||||
return DeviceConfig.getBoolean(
|
||||
"aconfig_test",
|
||||
"com.android.aconfig.test.enabled_rw",
|
||||
|
@ -151,10 +167,10 @@ mod tests {
|
|||
let expected_featureflags_content = r#"
|
||||
package com.android.aconfig.test;
|
||||
public interface FeatureFlags {
|
||||
boolean disabled_ro();
|
||||
boolean disabled_rw();
|
||||
boolean enabled_ro();
|
||||
boolean enabled_rw();
|
||||
boolean disabledRo();
|
||||
boolean disabledRw();
|
||||
boolean enabledRo();
|
||||
boolean enabledRw();
|
||||
}
|
||||
"#;
|
||||
let mut file_set = HashMap::from([
|
||||
|
@ -180,4 +196,12 @@ mod tests {
|
|||
|
||||
assert!(file_set.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_java_method_name() {
|
||||
let input = "____some_snake___name____";
|
||||
let expected = "someSnakeName";
|
||||
let formatted_name = format_java_method_name(input);
|
||||
assert_eq!(expected, formatted_name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import static com.android.aconfig.test.Flags.disabled_ro;
|
||||
import static com.android.aconfig.test.Flags.disabled_rw;
|
||||
import static com.android.aconfig.test.Flags.enabled_ro;
|
||||
import static com.android.aconfig.test.Flags.enabled_rw;
|
||||
import static com.android.aconfig.test.Flags.disabledRo;
|
||||
import static com.android.aconfig.test.Flags.disabledRw;
|
||||
import static com.android.aconfig.test.Flags.enabledRo;
|
||||
import static com.android.aconfig.test.Flags.enabledRw;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
@ -13,25 +13,25 @@ import org.junit.runners.JUnit4;
|
|||
public final class AconfigTest {
|
||||
@Test
|
||||
public void testDisabledReadOnlyFlag() {
|
||||
assertFalse(disabled_ro());
|
||||
assertFalse(disabledRo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnabledReadOnlyFlag() {
|
||||
// TODO: change to assertTrue(enabled_ro()) when the build supports reading tests/*.values
|
||||
// TODO: change to assertTrue(enabledRo()) when the build supports reading tests/*.values
|
||||
// (currently all flags are assigned the default READ_ONLY + DISABLED)
|
||||
assertFalse(enabled_ro());
|
||||
assertFalse(enabledRo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisabledReadWriteFlag() {
|
||||
assertFalse(disabled_rw());
|
||||
assertFalse(disabledRw());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnabledReadWriteFlag() {
|
||||
// TODO: change to assertTrue(enabled_rw()) when the build supports reading tests/*.values
|
||||
// TODO: change to assertTrue(enabledRw()) when the build supports reading tests/*.values
|
||||
// (currently all flags are assigned the default READ_ONLY + DISABLED)
|
||||
assertFalse(enabled_rw());
|
||||
assertFalse(enabledRw());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue