/*
* Copyright 2017-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package com.facebook.buck.android;
import com.google.common.collect.ImmutableList;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
public class Aapt2LinkTest {
@Test
public void testRDotTxtGeneration() {
List<String> javaLines =
ImmutableList.of(
"/* AUTO-GENERATED FILE. DO NOT MODIFY.",
" *",
" * This class was automatically generated by the",
" * aapt tool from the resource data it found. It",
" * should not be modified by hand.",
" */",
"",
"package make.r.txt;",
"",
"public final class R {",
" public static final class animator {",
" public static final int animator_1=0x7f020000;",
" public static final int animator_2=0x7f020001;",
" }",
" public static final class array {",
" public static final int some_sort_of_array=0x7f030007;",
" /**",
" * Very useful documentation.",
" */",
" public static final int another_array=0x7f03001f;",
" }",
" public static final class attr {",
" /**",
" * <p>Very structured documentation",
" * \"<code>@[+][<i>package</i>:]<i>type</i>/<i>name</i></code>\" or a theme",
" * with '\\\\n' backslashes",
" * and {@link android.view.MenuItem#setActionView(android.view.View)}",
" */",
" public static final int AndItsCamelCase=0x7f040000;",
" }",
" public static final class styleable {",
" public static final int[] ActionBarLayout={",
" 0x010100b3",
" };",
" public static final int ActionBarLayout_android_layout_gravity=0;",
" public static final int[] ActionLinkButton={",
" 0x7f040027, 0x7f040028",
" };",
" public static final int ActionLinkButton_actionLinkText=0;",
" public static final int ActionLinkButton_actionLinkUrl=1;",
" public static final int[] ActionMenuView={",
" };",
" public static final int[] ActionMode={",
" 0x7f0400a4, 0x7f0400b2, 0x7f04015d, 0x7f040361, ",
" 0x7f0406bf, 0x7f04075b",
" };",
" }",
" public static final class xml {",
" public static final int done=0x7f120000;",
" }",
"}");
List<String> expectedOutput =
ImmutableList.of(
"int animator animator_1 0x7f020000",
"int animator animator_2 0x7f020001",
"int array some_sort_of_array 0x7f030007",
"int array another_array 0x7f03001f",
"int attr AndItsCamelCase 0x7f040000",
"int[] styleable ActionBarLayout { 0x010100b3 }",
"int styleable ActionBarLayout_android_layout_gravity 0",
"int[] styleable ActionLinkButton { 0x7f040027,0x7f040028 }",
"int styleable ActionLinkButton_actionLinkText 0",
"int styleable ActionLinkButton_actionLinkUrl 1",
// Note, the whitespace on this output doesn't exactly match aapt output,
// but our parser tolerates it.
"int[] styleable ActionMenuView { }",
"int[] styleable ActionMode"
+ " { 0x7f0400a4,0x7f0400b2,0x7f04015d,0x7f040361,0x7f0406bf,0x7f04075b }",
"int xml done 0x7f120000");
List<String> txtLines = Aapt2Link.MakeRDotTxtStep.convertLines(javaLines);
Assert.assertEquals(expectedOutput, txtLines);
}
}