// Copyright 2021 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT //go:build !gogit package git import ( "testing" "github.com/stretchr/testify/assert" ) func TestParseTreeEntriesLong(t *testing.T) { objectFormat := Sha1ObjectFormat testCases := []struct { Input string Expected []*TreeEntry }{ { Input: `100644 blob ea0d83c9081af9500ac9f804101b3fd0a5c293af 8218 README.md 100644 blob 037f27dc9d353ae4fd50f0474b2194c593914e35 4681 README_ZH.md 100644 blob 9846a94f7e8350a916632929d0fda38c90dd2ca8 429 SECURITY.md 040000 tree 84b90550547016f73c5dd3f50dea662389e67b6d - assets `, Expected: []*TreeEntry{ { ID: MustIDFromString("ea0d83c9081af9500ac9f804101b3fd0a5c293af"), name: "README.md", entryMode: EntryModeBlob, size: 8218, sized: true, }, { ID: MustIDFromString("037f27dc9d353ae4fd50f0474b2194c593914e35"), name: "README_ZH.md", entryMode: EntryModeBlob, size: 4681, sized: true, }, { ID: MustIDFromString("9846a94f7e8350a916632929d0fda38c90dd2ca8"), name: "SECURITY.md", entryMode: EntryModeBlob, size: 429, sized: true, }, { ID: MustIDFromString("84b90550547016f73c5dd3f50dea662389e67b6d"), name: "assets", entryMode: EntryModeTree, sized: true, }, }, }, } for _, testCase := range testCases { entries, err := ParseTreeEntries(objectFormat, []byte(testCase.Input)) assert.NoError(t, err) assert.Len(t, entries, len(testCase.Expected)) for i, entry := range entries { assert.EqualValues(t, testCase.Expected[i], entry) } } } func TestParseTreeEntriesShort(t *testing.T) { objectFormat := Sha1ObjectFormat testCases := []struct { Input string Expected []*TreeEntry }{ { Input: `100644 blob ea0d83c9081af9500ac9f804101b3fd0a5c293af README.md 040000 tree 84b90550547016f73c5dd3f50dea662389e67b6d assets `, Expected: []*TreeEntry{ { ID: MustIDFromString("ea0d83c9081af9500ac9f804101b3fd0a5c293af"), name: "README.md", entryMode: EntryModeBlob, }, { ID: MustIDFromString("84b90550547016f73c5dd3f50dea662389e67b6d"), name: "assets", entryMode: EntryModeTree, }, }, }, } for _, testCase := range testCases { entries, err := ParseTreeEntries(objectFormat, []byte(testCase.Input)) assert.NoError(t, err) assert.Len(t, entries, len(testCase.Expected)) for i, entry := range entries { assert.EqualValues(t, testCase.Expected[i], entry) } } } func TestParseTreeEntriesInvalid(t *testing.T) { // there was a panic: "runtime error: slice bounds out of range" when the input was invalid: #20315 entries, err := ParseTreeEntries(Sha1ObjectFormat, []byte("100644 blob ea0d83c9081af9500ac9f804101b3fd0a5c293af")) assert.Error(t, err) assert.Len(t, entries, 0) } -10.0.14'>dependabot/maven/org.eclipse.jetty-jetty-server-10.0.14 Vaadin 6, 7, 8 is a Java framework for modern Java web applications: https://github.com/vaadin/frameworkwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main/java/com/vaadin/ui/renderers/ComponentRenderer.java
blob: 98a2002531b538d050b7711fdd6adcbaced7d6fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * Copyright 2000-2016 Vaadin Ltd.
 *
 * 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.vaadin.ui.renderers;

import com.vaadin.shared.ui.grid.renderers.ComponentRendererState;
import com.vaadin.ui.Component;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Label;

import elemental.json.Json;
import elemental.json.JsonValue;

/**
 * A renderer for presenting Components.
 * <p>
 * <strong>Note:</strong> The use of ComponentRenderer causes the Grid to
 * generate components for all items currently available in the client-side.
 * This means that a number of components is always generated and sent to the
 * client. Using complex structures of many nested components might be heavy to
 * generate and store, which will lead to performance problems.
 * <p>
 * <strong>Note:</strong> Components will occasionally be generated again during
 * runtime e.g. when selection changes. If your component has an internal state
 * that is not stored into the object, you should reuse the same component
 * instances.
 * <p>
 * Example of how to add a {@link Label} component to {@link Grid}:
 *
 * <pre>
 * Grid<Person> grid;
 * grid.addColumn(person -> new Label(person.getFullName()),
 *         new ComponentRenderer()).setCaption("Full Name");
 * </pre>
 *
 * @author Vaadin Ltd
 * @since 8.1
 */
@SuppressWarnings("serial")
public class ComponentRenderer extends AbstractRenderer<Object, Component> {

    /**
     * Constructor for ComponentRenderer.
     */
    public ComponentRenderer() {
        super(Component.class);
    }

    @Override
    public JsonValue encode(Component value) {
        return value != null ? Json.create(value.getConnectorId()) : null;
    }

    @Override
    protected ComponentRendererState getState(boolean markAsDirty) {
        return (ComponentRendererState) super.getState(markAsDirty);
    }

    @Override
    protected ComponentRendererState getState() {
        return (ComponentRendererState) super.getState();
    }
}